summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2014-01-30 12:26:09 -0500
committerGreg Hudson <ghudson@mit.edu>2014-01-30 18:33:09 -0500
commitb8a0c995d2a72cbfd2500de89e395e1ee10fc8e0 (patch)
tree59eb36035997eae707d88a50435d64a9d4739827
parent3c147860df11d8ef24dabf07d32f36915f3b640c (diff)
downloadkrb5-b8a0c995d2a72cbfd2500de89e395e1ee10fc8e0.zip
krb5-b8a0c995d2a72cbfd2500de89e395e1ee10fc8e0.tar.gz
krb5-b8a0c995d2a72cbfd2500de89e395e1ee10fc8e0.tar.xz
Add test case for ulog serial number wrapping
Add a unit test program named t_ulog. Make it map a ulog file, set up header state where kdb_last_sno is the last serial number, and then add an empty update. Check that the result is a ulog header with one update at serial number 1. ticket: 7839
-rw-r--r--.gitignore2
-rw-r--r--src/lib/kdb/Makefile.in10
-rw-r--r--src/lib/kdb/deps18
-rw-r--r--src/lib/kdb/libkdb5.exports1
-rw-r--r--src/lib/kdb/t_ulog.c88
5 files changed, 119 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index f96705e..3891897 100644
--- a/.gitignore
+++ b/.gitignore
@@ -183,6 +183,8 @@ testlog
/src/lib/kdb/adb_err.[ch]
/src/lib/kdb/t_stringattr
+/src/lib/kdb/t_ulog
+/src/lib/kdb/test.ulog
/src/lib/krb5/ccache/t_cc
/src/lib/krb5/ccache/t_cccursor
diff --git a/src/lib/kdb/Makefile.in b/src/lib/kdb/Makefile.in
index 826b1de..098db3f 100644
--- a/src/lib/kdb/Makefile.in
+++ b/src/lib/kdb/Makefile.in
@@ -45,10 +45,16 @@ STLIBOBJS= \
kdb_log.o \
keytab.o
+EXTRADEPSRCS= t_ulog.c
+
all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-liblinks clean-libs clean-libobjs
$(RM) adb_err.c adb_err.h t_stringattr.o t_stringattr
+ $(RM) t_ulog.o t_ulog test.ulog
+
+check-unix:: t_ulog
+ $(RUN_SETUP) $(VALGRIND) ./t_ulog test.ulog
check-pytests:: t_stringattr
$(RUNPYTEST) $(srcdir)/t_stringattr.py $(PYTESTFLAGS)
@@ -61,6 +67,10 @@ t_stringattr: t_stringattr.o $(KDB5_DEPLIBS) $(KADM_COMM_DEPLIBS) $(KRB5_BASE_DE
$(CC_LINK) -o $@ t_stringattr.o $(KDB5_LIBS) $(KADM_COMM_LIBS) \
$(KRB5_BASE_LIBS)
+t_ulog: t_ulog.o $(KDB5_DEPLIBS) $(KADM_COMM_DEPLIBS) $(KRB5_BASE_DEPLIBS)
+ $(CC_LINK) -o $@ t_ulog.o $(KDB5_LIBS) $(KADM_COMM_LIBS) \
+ $(KRB5_BASE_LIBS)
+
@lib_frag@
@libobj_frag@
diff --git a/src/lib/kdb/deps b/src/lib/kdb/deps
index 04a4142..dc48cb7 100644
--- a/src/lib/kdb/deps
+++ b/src/lib/kdb/deps
@@ -123,3 +123,21 @@ keytab.so keytab.po $(OUTPRE)keytab.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
$(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
$(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
$(top_srcdir)/include/socket-utils.h keytab.c
+t_ulog.so t_ulog.po $(OUTPRE)t_ulog.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
+ $(BUILDTOP)/include/gssapi/gssapi.h $(BUILDTOP)/include/gssrpc/types.h \
+ $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
+ $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/gssrpc/auth.h \
+ $(top_srcdir)/include/gssrpc/auth_gss.h $(top_srcdir)/include/gssrpc/auth_unix.h \
+ $(top_srcdir)/include/gssrpc/clnt.h $(top_srcdir)/include/gssrpc/rename.h \
+ $(top_srcdir)/include/gssrpc/rpc.h $(top_srcdir)/include/gssrpc/rpc_msg.h \
+ $(top_srcdir)/include/gssrpc/svc.h $(top_srcdir)/include/gssrpc/svc_auth.h \
+ $(top_srcdir)/include/gssrpc/xdr.h $(top_srcdir)/include/iprop.h \
+ $(top_srcdir)/include/iprop_hdr.h $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/kdb.h $(top_srcdir)/include/kdb_log.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
+ $(top_srcdir)/include/socket-utils.h t_ulog.c
diff --git a/src/lib/kdb/libkdb5.exports b/src/lib/kdb/libkdb5.exports
index 7f83ed2..e1c462e 100644
--- a/src/lib/kdb/libkdb5.exports
+++ b/src/lib/kdb/libkdb5.exports
@@ -85,6 +85,7 @@ krb5_db_delete_policy
krb5_db_free_policy
krb5_def_store_mkey_list
krb5_db_promote
+ulog_add_update
ulog_init_header
ulog_map
ulog_set_role
diff --git a/src/lib/kdb/t_ulog.c b/src/lib/kdb/t_ulog.c
new file mode 100644
index 0000000..9575837
--- /dev/null
+++ b/src/lib/kdb/t_ulog.c
@@ -0,0 +1,88 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* lib/kdb/t_ulog.c - Unit tests for KDB update log */
+/*
+ * Copyright (C) 2014 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This program performs unit tests for the update log functions in kdb_log.c.
+ * Right now it contains only a test for issue #7839, checking that
+ * ulog_add_update behaves appropriately when the last serial number is
+ * reached.
+ *
+ * The test program accepts one argument, which it unlinks and then maps with
+ * ulog_map(). This lets us test all of the update log functions except for
+ * ulog_replay(), which needs to open and modify a Kerberos database.
+ * ulog_replay is adequately exercised by the functional tests in t_iprop.py.
+ */
+
+#include "k5-int.h"
+#include "kdb_log.h"
+
+/* Use a zeroed context structure to avoid reading the profile. This works
+ * fine for the ulog functions. */
+static struct _krb5_context context_st;
+static krb5_context context = &context_st;
+
+int
+main(int argc, char **argv)
+{
+ kdb_log_context *lctx;
+ kdb_hlog_t *ulog;
+ kdb_incr_update_t upd;
+ const char *filename;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s filename\n", argv[0]);
+ exit(1);
+ }
+ filename = argv[1];
+ unlink(filename);
+
+ if (ulog_map(context, filename, 10, FKCOMMAND, NULL) != 0)
+ abort();
+ lctx = context->kdblog_context;
+ ulog = lctx->ulog;
+
+ /* Modify the ulog to look like it has reached the last serial number.
+ * Leave the timestamps at 0 and don't bother setting up the entries. */
+ ulog->kdb_num = lctx->ulogentries;
+ ulog->kdb_last_sno = (kdb_sno_t)-1;
+ ulog->kdb_first_sno = ulog->kdb_last_sno - ulog->kdb_num + 1;
+
+ /* Add an empty update. This should reinitialize the ulog, then add the
+ * update with serial number 1. */
+ memset(&upd, 0, sizeof(kdb_incr_update_t));
+ if (ulog_add_update(context, &upd) != 0)
+ abort();
+ assert(ulog->kdb_num == 1);
+ assert(ulog->kdb_first_sno == 1);
+ assert(ulog->kdb_last_sno == 1);
+ return 0;
+}