compat.c revision 65668
1126261Smlaier/*
2126258Smlaier * Copyright (c) 1999,2000 Markus Friedl.  All rights reserved.
3126258Smlaier *
4126258Smlaier * Redistribution and use in source and binary forms, with or without
5126258Smlaier * modification, are permitted provided that the following conditions
6126258Smlaier * are met:
7126258Smlaier * 1. Redistributions of source code must retain the above copyright
8126258Smlaier *    notice, this list of conditions and the following disclaimer.
9126258Smlaier * 2. Redistributions in binary form must reproduce the above copyright
10126258Smlaier *    notice, this list of conditions and the following disclaimer in the
11126258Smlaier *    documentation and/or other materials provided with the distribution.
12126258Smlaier *
13126258Smlaier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14126258Smlaier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15126258Smlaier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16126258Smlaier * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17126258Smlaier * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18126258Smlaier * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19126258Smlaier * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20126258Smlaier * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21126258Smlaier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22126258Smlaier * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23126258Smlaier */
24126258Smlaier
25126258Smlaier#include "includes.h"
26126258SmlaierRCSID("$OpenBSD: compat.c,v 1.23 2000/09/07 21:13:37 markus Exp $");
27126258Smlaier
28126258Smlaier#include "ssh.h"
29126258Smlaier#include "packet.h"
30126258Smlaier#include "xmalloc.h"
31126258Smlaier#include "compat.h"
32126258Smlaier
33126261Smlaierint compat13 = 0;
34126261Smlaierint compat20 = 0;
35126261Smlaierint datafellows = 0;
36126258Smlaier
37126258Smlaiervoid
38126258Smlaierenable_compat20(void)
39126258Smlaier{
40126258Smlaier	verbose("Enabling compatibility mode for protocol 2.0");
41126258Smlaier	compat20 = 1;
42126258Smlaier}
43126258Smlaiervoid
44126258Smlaierenable_compat13(void)
45126258Smlaier{
46126258Smlaier	verbose("Enabling compatibility mode for protocol 1.3");
47126258Smlaier	compat13 = 1;
48126258Smlaier}
49126258Smlaier/* datafellows bug compatibility */
50126258Smlaiervoid
51126258Smlaiercompat_datafellows(const char *version)
52126258Smlaier{
53126258Smlaier	int i;
54126258Smlaier	size_t len;
55126258Smlaier	struct {
56126258Smlaier		char	*version;
57126258Smlaier		int	bugs;
58126258Smlaier	} check[] = {
59126258Smlaier		{"2.1.0",	SSH_BUG_SIGBLOB|SSH_BUG_HMAC},
60126258Smlaier		{"2.0.1",	SSH_BUG_SIGBLOB|SSH_BUG_HMAC|SSH_BUG_PUBKEYAUTH|SSH_BUG_X11FWD},
61126258Smlaier		{"2.",		SSH_BUG_HMAC|SSH_COMPAT_SESSIONID_ENCODING},
62126258Smlaier		{NULL,		0}
63126258Smlaier	};
64126258Smlaier	/* process table, return first match */
65126258Smlaier	for (i = 0; check[i].version; i++) {
66126258Smlaier		len = strlen(check[i].version);
67126258Smlaier		if (strlen(version) >= len &&
68126258Smlaier		   (strncmp(version, check[i].version, len) == 0)) {
69126258Smlaier			verbose("datafellows: %.200s", version);
70126258Smlaier			datafellows = check[i].bugs;
71126258Smlaier			return;
72126258Smlaier		}
73126258Smlaier	}
74126258Smlaier}
75126258Smlaier
76126258Smlaier#define	SEP	","
77126258Smlaierint
78126258Smlaierproto_spec(const char *spec)
79126258Smlaier{
80	char *s, *p, *q;
81	int ret = SSH_PROTO_UNKNOWN;
82
83	if (spec == NULL)
84		return ret;
85	q = s = xstrdup(spec);
86	for ((p = strsep(&q, SEP)); p && *p != '\0'; (p = strsep(&q, SEP))) {
87		switch(atoi(p)) {
88		case 1:
89			if (ret == SSH_PROTO_UNKNOWN)
90				ret |= SSH_PROTO_1_PREFERRED;
91			ret |= SSH_PROTO_1;
92			break;
93		case 2:
94			ret |= SSH_PROTO_2;
95			break;
96		default:
97			log("ignoring bad proto spec: '%s'.", p);
98			break;
99		}
100	}
101	xfree(s);
102	return ret;
103}
104