1 /* $NetBSD: test_sequence.c,v 1.1.1.1 2011/04/13 18:14:46 elric Exp $ */
4 * Copyright (c) 2003 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "gsskrb5_locl.h"
38 /* correct ordering */
39 OM_uint32 pattern1
[] = {
40 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
44 OM_uint32 pattern2
[] = {
45 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13
49 OM_uint32 pattern3
[] = {
50 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13
54 OM_uint32 pattern4
[] = {
55 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16, 18, 100
59 OM_uint32 pattern5
[] = {
60 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
64 OM_uint32 pattern6
[] = {
65 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
66 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
67 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
68 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
69 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
70 50, 51, 52, 53, 54, 55, 56, 57, 58, 59
74 OM_uint32 pattern7
[] = {
79 OM_uint32 pattern8
[] = {
80 4294967293U, 4294967294U, 4294967295U, 0, 1, 2
84 test_seq(int t
, OM_uint32 flags
, OM_uint32 start_seq
,
85 OM_uint32
*pattern
, int pattern_len
, OM_uint32 expected_error
)
87 struct gss_msg_order
*o
;
88 OM_uint32 maj_stat
, min_stat
;
92 maj_stat
= _gssapi_msg_order_create(&min_stat
, &o
, flags
,
95 errx(1, "create: %d %d", maj_stat
, min_stat
);
97 sp
= krb5_storage_emem();
99 errx(1, "krb5_storage_from_emem");
101 _gssapi_msg_order_export(sp
, o
);
103 for (i
= 0; i
< pattern_len
; i
++) {
104 maj_stat
= _gssapi_msg_order_check(o
, pattern
[i
]);
108 if (maj_stat
!= expected_error
) {
109 printf("test pattern %d failed with %d (should have been %d)\n",
110 t
, maj_stat
, expected_error
);
111 krb5_storage_free(sp
);
112 _gssapi_msg_order_destroy(&o
);
117 _gssapi_msg_order_destroy(&o
);
119 /* try again, now with export/imported blob */
120 krb5_storage_seek(sp
, 0, SEEK_SET
);
122 maj_stat
= _gssapi_msg_order_import(&min_stat
, sp
, &o
);
124 errx(1, "import: %d %d", maj_stat
, min_stat
);
126 for (i
= 0; i
< pattern_len
; i
++) {
127 maj_stat
= _gssapi_msg_order_check(o
, pattern
[i
]);
131 if (maj_stat
!= expected_error
) {
132 printf("import/export test pattern %d failed "
133 "with %d (should have been %d)\n",
134 t
, maj_stat
, expected_error
);
135 _gssapi_msg_order_destroy(&o
);
136 krb5_storage_free(sp
);
140 _gssapi_msg_order_destroy(&o
);
141 krb5_storage_free(sp
);
150 OM_uint32 error_code
;
154 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
156 sizeof(pattern1
)/sizeof(pattern1
[0]),
160 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
162 sizeof(pattern2
)/sizeof(pattern2
[0]),
166 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
168 sizeof(pattern3
)/sizeof(pattern3
[0]),
169 GSS_S_DUPLICATE_TOKEN
172 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
174 sizeof(pattern4
)/sizeof(pattern4
[0]),
178 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
180 sizeof(pattern5
)/sizeof(pattern5
[0]),
184 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
186 sizeof(pattern6
)/sizeof(pattern6
[0]),
190 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
192 sizeof(pattern7
)/sizeof(pattern7
[0]),
196 GSS_C_REPLAY_FLAG
|GSS_C_SEQUENCE_FLAG
,
198 sizeof(pattern8
)/sizeof(pattern8
[0]),
205 sizeof(pattern1
)/sizeof(pattern1
[0]),
211 sizeof(pattern2
)/sizeof(pattern2
[0]),
217 sizeof(pattern3
)/sizeof(pattern3
[0]),
223 sizeof(pattern4
)/sizeof(pattern4
[0]),
229 sizeof(pattern5
)/sizeof(pattern5
[0]),
235 sizeof(pattern6
)/sizeof(pattern6
[0]),
241 sizeof(pattern7
)/sizeof(pattern7
[0]),
247 sizeof(pattern8
)/sizeof(pattern8
[0]),
255 sizeof(pattern1
)/sizeof(pattern1
[0]),
261 sizeof(pattern2
)/sizeof(pattern2
[0]),
267 sizeof(pattern3
)/sizeof(pattern3
[0]),
268 GSS_S_DUPLICATE_TOKEN
273 sizeof(pattern4
)/sizeof(pattern4
[0]),
279 sizeof(pattern5
)/sizeof(pattern5
[0]),
285 sizeof(pattern6
)/sizeof(pattern6
[0]),
291 sizeof(pattern7
)/sizeof(pattern7
[0]),
297 sizeof(pattern8
)/sizeof(pattern8
[0]),
304 sizeof(pattern1
)/sizeof(pattern1
[0]),
310 sizeof(pattern2
)/sizeof(pattern2
[0]),
316 sizeof(pattern3
)/sizeof(pattern3
[0]),
317 GSS_S_DUPLICATE_TOKEN
322 sizeof(pattern4
)/sizeof(pattern4
[0]),
328 sizeof(pattern5
)/sizeof(pattern5
[0]),
334 sizeof(pattern6
)/sizeof(pattern6
[0]),
340 sizeof(pattern7
)/sizeof(pattern7
[0]),
346 sizeof(pattern8
)/sizeof(pattern8
[0]),
353 main(int argc
, char **argv
)
357 for (i
= 0; i
< sizeof(pl
)/sizeof(pl
[0]); i
++) {
367 printf("FAILED %d tests\n", failed
);