]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add test case for ulog serial number wrapping
authorGreg Hudson <ghudson@mit.edu>
Thu, 30 Jan 2014 17:26:09 +0000 (12:26 -0500)
committerGreg Hudson <ghudson@mit.edu>
Thu, 30 Jan 2014 23:33:09 +0000 (18:33 -0500)
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

.gitignore
src/lib/kdb/Makefile.in
src/lib/kdb/deps
src/lib/kdb/libkdb5.exports
src/lib/kdb/t_ulog.c [new file with mode: 0644]

index f96705e957ba8d209876108daa5ee61321890dcb..38918979fffe9a3408ca9f36dcc505784e9a84da 100644 (file)
@@ -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
index 826b1de9fb6ec56ce2559489e623170da7ee3c03..098db3f80405cc74b312e701d128b24ba6cc5af4 100644 (file)
@@ -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@
 
index 04a4142deefbe2dc73b7543cda0a15a6a048ed05..dc48cb71dcd0be04f900778d54a88db41d18f7eb 100644 (file)
@@ -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
index 7f83ed2a9ed23aae9ebbe11315369b10d5db329b..e1c462efe56ac0e4d46973dd83e1cc231348b0f8 100644 (file)
@@ -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 (file)
index 0000000..9575837
--- /dev/null
@@ -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;
+}