krb5 commit: Clean up replay cache tests

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/ad6ba3a46b07aee4a8bb44ec4fb4cdc320edaa5a
commit ad6ba3a46b07aee4a8bb44ec4fb4cdc320edaa5a
Author: Greg Hudson <[email protected]>
Date:   Wed Jul 31 16:21:46 2019 -0400

    Clean up replay cache tests
    
    Remove t_replay.c, which wasn't used or built by default and no longer
    works with the simplified replay cache interface.  Add t_rcfile2.c to
    the sources and rebuild dependencies.

 src/lib/krb5/rcache/Makefile.in |    7 +-
 src/lib/krb5/rcache/deps        |   17 ++--
 src/lib/krb5/rcache/t_replay.c  |  265 ---------------------------------------
 3 files changed, 10 insertions(+), 279 deletions(-)

diff --git a/src/lib/krb5/rcache/Makefile.in b/src/lib/krb5/rcache/Makefile.in
index 5db08dd..c507f44 100644
--- a/src/lib/krb5/rcache/Makefile.in
+++ b/src/lib/krb5/rcache/Makefile.in
@@ -29,7 +29,7 @@ SRCS=	\
 	$(srcdir)/rc_none.c	\
 	$(srcdir)/ser_rc.c	\
 	$(srcdir)/t_memrcache.c	\
-	$(srcdir)/t_replay.c
+	$(srcdir)/t_rcfile2.c
 
 ##DOS##LIBOBJS = $(OBJS)
 
@@ -42,11 +42,6 @@ t_memrcache: t_memrcache.o $(KRB5_BASE_DEPLIBS)
 t_rcfile2: t_rcfile2.o $(KRB5_BASE_DEPLIBS)
 	$(CC_LINK) -o $@ t_rcfile2.o $(KRB5_BASE_LIBS)
 
-T_REPLAY_OBJS= t_replay.o
-
-t_replay: $(T_REPLAY_OBJS) $(KRB5_BASE_DEPLIBS)
-	$(CC_LINK) -o t_replay $(T_REPLAY_OBJS) $(KRB5_BASE_LIBS)
-
 check-unix: t_memrcache t_rcfile2
 	$(RUN_TEST) ./t_memrcache
 	$(RUN_TEST) ./t_rcfile2 testrcache expiry 10000
diff --git a/src/lib/krb5/rcache/deps b/src/lib/krb5/rcache/deps
index b9a63cf..bf27a81 100644
--- a/src/lib/krb5/rcache/deps
+++ b/src/lib/krb5/rcache/deps
@@ -77,14 +77,15 @@ t_memrcache.so t_memrcache.po $(OUTPRE)t_memrcache.$(OBJEXT): \
   $(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 \
   memrcache.c memrcache.h t_memrcache.c
-t_replay.so t_replay.po $(OUTPRE)t_replay.$(OBJEXT): \
+t_rcfile2.so t_rcfile2.po $(OUTPRE)t_rcfile2.$(OBJEXT): \
   $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
   $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
   $(COM_ERR_DEPS) $(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/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_replay.c
+  $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-hashtab.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/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 rc-int.h rc_file2.c \
+  t_rcfile2.c
diff --git a/src/lib/krb5/rcache/t_replay.c b/src/lib/krb5/rcache/t_replay.c
deleted file mode 100644
index b99cdf1..0000000
--- a/src/lib/krb5/rcache/t_replay.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* lib/krb5/rcache/t_replay.c - Test harness for replay cache */
-/*
- * Copyright (C) 2009 by the Massachusetts Institute of Technology.
- * All rights reserved.
- *
- * Export of this software from the United States of America may
- *   require a specific license from the United States Government.
- *   It is the responsibility of any person or organization contemplating
- *   export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission.  Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose.  It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "k5-int.h"
-
-static void
-usage(const char *progname)
-{
-    fprintf(stderr, "%s: Usage:\n", progname);
-    fprintf(stderr, "  %s dump <filename>\n", progname);
-    fprintf(stderr, "  %s store <rc> <cli> <srv> <msg> <tstamp> <usec>"
-            " <now> <now-usec>\n", progname);
-    fprintf(stderr, "  %s expunge <rc> <now> <now-usec>\n", progname);
-    exit(1);
-}
-
-static char *
-read_counted_string(FILE *fp)
-{
-    unsigned int len;
-    char *str;
-
-    if (fread(&len, sizeof(len), 1, fp) != 1)
-        return NULL;
-    if (len == 0 || len > 10000)
-        return NULL;
-    if ((str = malloc(len)) == NULL)
-        return NULL;
-    if (fread(str, 1, len, fp) != len)
-        return NULL;
-    if (str[len - 1] != 0)
-        return NULL;
-    return str;
-}
-
-static void
-dump_rcache(const char *filename)
-{
-    FILE *fp;
-    krb5_deltat lifespan;
-    krb5_int16 vno;
-    char *str;
-    krb5_int32 usec;
-    krb5_timestamp timestamp;
-
-    fp = fopen(filename, "r");
-    if (!fp) {
-        fprintf(stderr, "Can't open filename: %s\n", strerror(errno));
-        return;
-    }
-    if (fread(&vno, sizeof(vno), 1, fp) != 1)
-        return;
-    if (fread(&lifespan, sizeof(lifespan), 1, fp) != 1)
-        return;
-    printf("Lifespan: %ld\n", (long) lifespan);
-    while (1) {
-        printf("---\n");
-
-        if (!(str = read_counted_string(fp)))
-            return;
-        printf("Client: %s\n", str);
-        free(str);
-
-        if (!(str = read_counted_string(fp)))
-            return;
-        printf("Server: %s\n", str);
-        free(str);
-
-        if (fread(&usec, sizeof(usec), 1, fp) != 1)
-            return;
-        printf("Microseconds: %ld\n", (long) usec);
-
-        if (fread(&timestamp, sizeof(timestamp), 1, fp) != 1)
-            return;
-        printf("Timestamp: %ld\n", (long) timestamp);
-    }
-}
-
-static void
-store(krb5_context ctx, char *rcspec, char *client, char *server, char *msg,
-      krb5_timestamp timestamp, krb5_int32 usec, krb5_timestamp now_timestamp,
-      krb5_int32 now_usec)
-{
-    krb5_rcache rc = NULL;
-    krb5_error_code retval = 0;
-    char *hash = NULL;
-    krb5_donot_replay rep;
-    krb5_data d;
-
-    if (now_timestamp != 0)
-        krb5_set_debugging_time(ctx, now_timestamp, now_usec);
-    if ((retval = krb5_rc_resolve_full(ctx, &rc, rcspec)))
-        goto cleanup;
-    if ((retval = krb5_rc_recover_or_initialize(ctx, rc, ctx->clockskew)))
-        goto cleanup;
-    if (msg) {
-        d.data = msg;
-        d.length = strlen(msg);
-        if ((retval = krb5_rc_hash_message(ctx, &d, &hash)))
-            goto cleanup;
-    }
-    rep.client = client;
-    rep.server = server;
-    rep.msghash = hash;
-    rep.cusec = usec;
-    rep.ctime = timestamp;
-    retval = krb5_rc_store(ctx, rc, &rep);
-cleanup:
-    if (retval == KRB5KRB_AP_ERR_REPEAT)
-        printf("Replay\n");
-    else if (!retval)
-        printf("Entry successfully stored\n");
-    else
-        fprintf(stderr, "Failure: %s\n", krb5_get_error_message(ctx, retval));
-    if (rc)
-        krb5_rc_close(ctx, rc);
-    if (hash)
-        free(hash);
-}
-
-static void
-expunge(krb5_context ctx, char *rcspec, krb5_timestamp now_timestamp,
-        krb5_int32 now_usec)
-{
-    krb5_rcache rc = NULL;
-    krb5_error_code retval = 0;
-
-    if (now_timestamp > 0)
-        krb5_set_debugging_time(ctx, now_timestamp, now_usec);
-    if ((retval = krb5_rc_resolve_full(ctx, &rc, rcspec)))
-        goto cleanup;
-    if ((retval = krb5_rc_recover_or_initialize(ctx, rc, ctx->clockskew)))
-        goto cleanup;
-    retval = krb5_rc_expunge(ctx, rc);
-cleanup:
-    if (!retval)
-        printf("Cache successfully expunged\n");
-    else
-        fprintf(stderr, "Failure: %s\n", krb5_get_error_message(ctx, retval));
-    if (rc)
-        krb5_rc_close(ctx, rc);
-}
-
-int
-main(int argc, char **argv)
-{
-    krb5_context ctx;
-    krb5_error_code retval;
-    const char *progname;
-
-    retval = krb5_init_context(&ctx);
-    if (retval) {
-        fprintf(stderr, "krb5_init_context returned error %ld\n",
-                (long) retval);
-        exit(1);
-    }
-    progname = argv[0];
-
-    /* Parse arguments. */
-    argc--; argv++;
-    while (argc) {
-        if (strcmp(*argv, "dump") == 0) {
-            /*
-             * Without going through the rcache interface, dump a
-             * named dfl-format rcache file to stdout.  Takes a full
-             * pathname argument.
-             */
-            const char *filename;
-
-            argc--; argv++;
-            if (!argc) usage(progname);
-            filename = *argv;
-            dump_rcache(filename);
-        } else if (strcmp(*argv, "store") == 0) {
-            /*
-             * Using the rcache interface, store a replay record.
-             * Takes an rcache spec like dfl:host as the first
-             * argument.  If non-empty, the "msg" argument will be
-             * hashed and provided in the replay record.  The
-             * now-timestamp argument can be 0 to use the current
-             * time.
-             */
-            char *rcspec, *client, *server, *msg;
-            krb5_timestamp timestamp, now_timestamp;
-            krb5_int32 usec, now_usec;
-
-            argc--; argv++;
-            if (!argc) usage(progname);
-            rcspec = *argv;
-            argc--; argv++;
-            if (!argc) usage(progname);
-            client = *argv;
-            argc--; argv++;
-            if (!argc) usage(progname);
-            server = *argv;
-            argc--; argv++;
-            if (!argc) usage(progname);
-            msg = (**argv) ? *argv : NULL;
-            argc--; argv++;
-            if (!argc) usage(progname);
-            timestamp = (krb5_timestamp) atoll(*argv);
-            argc--; argv++;
-            if (!argc) usage(progname);
-            usec = (krb5_int32) atol(*argv);
-            argc--; argv++;
-            if (!argc) usage(progname);
-            now_timestamp = (krb5_timestamp) atoll(*argv);
-            argc--; argv++;
-            if (!argc) usage(progname);
-            now_usec = (krb5_int32) atol(*argv);
-
-            store(ctx, rcspec, client, server, msg, timestamp, usec,
-                  now_timestamp, now_usec);
-        } else if (strcmp(*argv, "expunge") == 0) {
-            /*
-             * Using the rcache interface, expunge a replay cache.
-             * The now-timestamp argument can be 0 to use the current
-             * time.
-             */
-            char *rcspec;
-            krb5_timestamp now_timestamp;
-            krb5_int32 now_usec;
-
-            argc--; argv++;
-            if (!argc) usage(progname);
-            rcspec = *argv;
-            argc--; argv++;
-            if (!argc) usage(progname);
-            now_timestamp = (krb5_timestamp) atoll(*argv);
-            argc--; argv++;
-            if (!argc) usage(progname);
-            now_usec = (krb5_int32) atol(*argv);
-            expunge(ctx, rcspec, now_timestamp, now_usec);
-        } else
-            usage(progname);
-        argc--; argv++;
-    }
-
-    krb5_free_context(ctx);
-
-    return 0;
-}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.