1276707Sdes/*
2276707Sdes * Copyright (c) 2014 Darren Tucker
3276707Sdes *
4276707Sdes * Permission to use, copy, modify, and distribute this software for any
5276707Sdes * purpose with or without fee is hereby granted, provided that the above
6276707Sdes * copyright notice and this permission notice appear in all copies.
7276707Sdes *
8276707Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9276707Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10276707Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11276707Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12276707Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13276707Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14276707Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15276707Sdes */
16276707Sdes
17276707Sdes#include <stdio.h>
18276707Sdes#include <stdlib.h>
19276707Sdes
20276707Sdesint ssh_compatible_openssl(long, long);
21276707Sdes
22276707Sdesstruct version_test {
23276707Sdes	long headerver;
24276707Sdes	long libver;
25276707Sdes	int result;
26276707Sdes} version_tests[] = {
27276707Sdes	/* built with 0.9.8b release headers */
28276707Sdes	{ 0x0090802fL, 0x0090802fL, 1},	/* exact match */
29276707Sdes	{ 0x0090802fL, 0x0090804fL, 1},	/* newer library fix version: ok */
30276707Sdes	{ 0x0090802fL, 0x0090801fL, 1},	/* older library fix version: ok */
31276707Sdes	{ 0x0090802fL, 0x0090702fL, 0},	/* older library minor version: NO */
32276707Sdes	{ 0x0090802fL, 0x0090902fL, 0},	/* newer library minor version: NO */
33276707Sdes	{ 0x0090802fL, 0x0080802fL, 0},	/* older library major version: NO */
34276707Sdes	{ 0x0090802fL, 0x1000100fL, 0},	/* newer library major version: NO */
35276707Sdes
36276707Sdes	/* built with 1.0.1b release headers */
37276707Sdes	{ 0x1000101fL, 0x1000101fL, 1},/* exact match */
38276707Sdes	{ 0x1000101fL, 0x1000102fL, 1},	/* newer library patch version: ok */
39276707Sdes	{ 0x1000101fL, 0x1000100fL, 1},	/* older library patch version: ok */
40276707Sdes	{ 0x1000101fL, 0x1000201fL, 1},	/* newer library fix version: ok */
41276707Sdes	{ 0x1000101fL, 0x1000001fL, 0},	/* older library fix version: NO */
42276707Sdes	{ 0x1000101fL, 0x1010101fL, 0},	/* newer library minor version: NO */
43276707Sdes	{ 0x1000101fL, 0x0000101fL, 0},	/* older library major version: NO */
44276707Sdes	{ 0x1000101fL, 0x2000101fL, 0},	/* newer library major version: NO */
45276707Sdes};
46276707Sdes
47276707Sdesvoid
48276707Sdesfail(long hver, long lver, int result)
49276707Sdes{
50276707Sdes	fprintf(stderr, "opensslver: header %lx library %lx != %d \n", hver, lver, result);
51276707Sdes	exit(1);
52276707Sdes}
53276707Sdes
54276707Sdesint
55276707Sdesmain(void)
56276707Sdes{
57276707Sdes	unsigned int i;
58276707Sdes	int res;
59276707Sdes	long hver, lver;
60276707Sdes
61276707Sdes	for (i = 0; i < sizeof(version_tests) / sizeof(version_tests[0]); i++) {
62276707Sdes		hver = version_tests[i].headerver;
63276707Sdes		lver = version_tests[i].libver;
64276707Sdes		res = version_tests[i].result;
65276707Sdes		if (ssh_compatible_openssl(hver, lver) != res)
66276707Sdes			fail(hver, lver, res);
67276707Sdes	}
68276707Sdes	exit(0);
69276707Sdes}
70