annotate cli-algo.c @ 221:a4b93a2ed879

* close a file descriptor after we've shutdown() both sides, to avoid a leak
author Matt Johnston <matt@ucc.asn.au>
date Fri, 08 Jul 2005 15:04:06 +0000
parents 0cfba3034be5
children 870c63519757
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 * SSH client implementation
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 *
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * Copyright (c) 2002,2003 Matt Johnston
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * Copyright (c) 2004 by Mihnea Stoenescu
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * All rights reserved.
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 *
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * of this software and associated documentation files (the "Software"), to deal
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * in the Software without restriction, including without limitation the rights
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 * copies of the Software, and to permit persons to whom the Software is
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * furnished to do so, subject to the following conditions:
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 *
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 * The above copyright notice and this permission notice shall be included in
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * all copies or substantial portions of the Software.
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 *
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 * SOFTWARE. */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "algo.h"
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "dbutil.h"
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 /*
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 * The chosen [encryption | MAC | compression] algorithm to each
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 * direction MUST be the first algorithm on the client's list
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 * that is also on the server's list.
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 */
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
36 algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
37 int *goodguess) {
25
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 unsigned char * algolist = NULL;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 unsigned char * remotealgos[MAX_PROPOSED_ALGO];
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 unsigned int len;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 unsigned int count, i, j;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 algo_type * ret = NULL;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
45 *goodguess = 0;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
46
25
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 algolist = buf_getstring(buf, &len);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
49 TRACE(("cli_buf_match_algo: %s", algolist))
25
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 if (len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 goto out; /* just a sanity check, no other use */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 /* remotealgos will contain a list of the strings parsed out */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 /* We will have at least one string (even if it's just "") */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 remotealgos[0] = algolist;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 count = 1;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 /* Iterate through, replacing ','s with NULs, to split it into
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 * words. */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 for (i = 0; i < len; i++) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 if (algolist[i] == '\0') {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 /* someone is trying something strange */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 goto out;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 if (algolist[i] == ',') {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 algolist[i] = '\0';
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 remotealgos[count] = &algolist[i+1];
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 count++;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 if (count == MAX_PROPOSED_ALGO) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 break;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 /* iterate and find the first match */
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 for (j = 0; localalgos[j].name != NULL; j++) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 if (localalgos[j].usable) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 len = strlen(localalgos[j].name);
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 for (i = 0; i < count; i++) {
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 if (len == strlen(remotealgos[i])
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 && strncmp(localalgos[j].name,
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 remotealgos[i], len) == 0) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
84 if (i == 0 && j == 0) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
85 /* was a good guess */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
86 *goodguess = 1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 25
diff changeset
87 }
25
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 ret = &localalgos[j];
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 goto out;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 out:
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 m_free(algolist);
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 return ret;
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 }
e4b6e2d569b2 Rename cli_algo.c to cli-algo.c for consistency
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99