Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/lib/kdb/t_ulog.c
39566 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* lib/kdb/t_ulog.c - Unit tests for KDB update log */
3
/*
4
* Copyright (C) 2014 by the Massachusetts Institute of Technology.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
*
14
* * Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in
16
* the documentation and/or other materials provided with the
17
* distribution.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30
* OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
/*
34
* This program performs unit tests for the update log functions in kdb_log.c.
35
* Right now it contains only a test for issue #7839, checking that
36
* ulog_add_update behaves appropriately when the last serial number is
37
* reached.
38
*
39
* The test program accepts one argument, which it unlinks and then maps with
40
* ulog_map(). This lets us test all of the update log functions except for
41
* ulog_replay(), which needs to open and modify a Kerberos database.
42
* ulog_replay is adequately exercised by the functional tests in t_iprop.py.
43
*/
44
45
#include "k5-int.h"
46
#include "kdb_log.h"
47
48
/* Use a zeroed context structure to avoid reading the profile. This works
49
* fine for the ulog functions. */
50
static struct _krb5_context context_st;
51
static krb5_context context = &context_st;
52
53
int
54
main(int argc, char **argv)
55
{
56
kdb_log_context *lctx;
57
kdb_hlog_t *ulog;
58
kdb_incr_update_t upd;
59
const char *filename;
60
61
if (argc != 2) {
62
fprintf(stderr, "Usage: %s filename\n", argv[0]);
63
exit(1);
64
}
65
filename = argv[1];
66
unlink(filename);
67
68
if (ulog_map(context, filename, 10) != 0)
69
abort();
70
lctx = context->kdblog_context;
71
ulog = lctx->ulog;
72
73
/* Modify the ulog to look like it has reached the last serial number.
74
* Leave the timestamps at 0 and don't bother setting up the entries. */
75
ulog->kdb_num = lctx->ulogentries;
76
ulog->kdb_last_sno = (kdb_sno_t)-1;
77
ulog->kdb_first_sno = ulog->kdb_last_sno - ulog->kdb_num + 1;
78
79
/* Add an empty update. This should reinitialize the ulog, then add the
80
* update with serial number 2. */
81
memset(&upd, 0, sizeof(kdb_incr_update_t));
82
if (ulog_add_update(context, &upd) != 0)
83
abort();
84
assert(ulog->kdb_num == 2);
85
assert(ulog->kdb_first_sno == 1);
86
assert(ulog->kdb_last_sno == 2);
87
return 0;
88
}
89
90