comparison svr-algo.c @ 4:fe6bca95afa7

Makefile.in contains updated files required
author Matt Johnston <matt@ucc.asn.au>
date Tue, 01 Jun 2004 02:46:09 +0000
parents
children 0969767bca0d
comparison
equal deleted inserted replaced
-1:000000000000 4:fe6bca95afa7
1 #include "algo.h"
2 #include "dbutil.h"
3
4 /* match the first algorithm in the comma-separated list in buf which is
5 * also in localalgos[], or return NULL on failure.
6 * (*goodguess) is set to 1 if the preferred client/server algos match,
7 * 0 otherwise. This is used for checking if the kexalgo/hostkeyalgos are
8 * guessed correctly */
9 algo_type * svr_buf_match_algo(buffer* buf, algo_type localalgos[],
10 int *goodguess)
11 {
12
13 unsigned char * algolist = NULL;
14 unsigned char * remotealgos[MAX_PROPOSED_ALGO];
15 unsigned int len;
16 unsigned int count, i, j;
17 algo_type * ret = NULL;
18
19 /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
20 algolist = buf_getstring(buf, &len);
21 /* Debug this */
22 TRACE(("buf_match_algo: %s", algolist));
23 if (len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
24 goto out; /* just a sanity check, no other use */
25 }
26
27 /* remotealgos will contain a list of the strings parsed out */
28 /* We will have at least one string (even if it's just "") */
29 remotealgos[0] = algolist;
30 count = 1;
31 /* Iterate through, replacing ','s with NULs, to split it into
32 * words. */
33 for (i = 0; i < len; i++) {
34 if (algolist[i] == '\0') {
35 /* someone is trying something strange */
36 goto out;
37 }
38 if (algolist[i] == ',') {
39 algolist[i] = '\0';
40 remotealgos[count] = &algolist[i+1];
41 count++;
42 }
43 if (count == MAX_PROPOSED_ALGO) {
44 break;
45 }
46 }
47
48 /* iterate and find the first match */
49 for (i = 0; i < count; i++) {
50
51 len = strlen(remotealgos[i]);
52
53 for (j = 0; localalgos[j].name != NULL; j++) {
54 if (localalgos[j].usable) {
55 if (len == strlen(localalgos[j].name) &&
56 strncmp(localalgos[j].name, remotealgos[i], len) == 0) {
57 /* set if it was a good guess */
58 if (i == 0 && j == 0) {
59 *goodguess = 1;
60 } else {
61 *goodguess = 0;
62 }
63 /* set the algo to return */
64 ret = &localalgos[j];
65 goto out;
66 }
67 }
68 }
69 }
70
71 out:
72 m_free(algolist);
73 return ret;
74 }