summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth-rsa.c2
-rw-r--r--channels.c79
-rw-r--r--cipher.c2
-rw-r--r--mpaux.c2
-rw-r--r--scp.c8
-rw-r--r--ssh-add.c88
-rw-r--r--ssh-agent.c11
-rw-r--r--ssh.c4
-rw-r--r--sshconnect.c2
9 files changed, 84 insertions, 114 deletions
diff --git a/auth-rsa.c b/auth-rsa.c
index 076f8a3e4..3be37ffcb 100644
--- a/auth-rsa.c
+++ b/auth-rsa.c
@@ -17,7 +17,7 @@ validity of the host key.
17 17
18#include "config.h" 18#include "config.h"
19#include "includes.h" 19#include "includes.h"
20RCSID("$Id: auth-rsa.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 20RCSID("$Id: auth-rsa.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
21 21
22#include "rsa.h" 22#include "rsa.h"
23#include "packet.h" 23#include "packet.h"
diff --git a/channels.c b/channels.c
index 38a65a07f..29a842fcf 100644
--- a/channels.c
+++ b/channels.c
@@ -16,7 +16,7 @@ arbitrary tcp/ip connections, and the authentication agent connection.
16*/ 16*/
17 17
18#include "includes.h" 18#include "includes.h"
19RCSID("$Id: channels.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); 19RCSID("$Id: channels.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
20 20
21#include "ssh.h" 21#include "ssh.h"
22#include "packet.h" 22#include "packet.h"
@@ -108,7 +108,8 @@ void channel_permit_all_opens()
108 108
109int channel_allocate(int type, int sock, char *remote_name) 109int channel_allocate(int type, int sock, char *remote_name)
110{ 110{
111 int i, old_channels; 111 int i, found;
112 Channel *c;
112 113
113 /* Update the maximum file descriptor value. */ 114 /* Update the maximum file descriptor value. */
114 if (sock > channel_max_fd_value) 115 if (sock > channel_max_fd_value)
@@ -128,41 +129,38 @@ int channel_allocate(int type, int sock, char *remote_name)
128 } 129 }
129 130
130 /* Try to find a free slot where to put the new channel. */ 131 /* Try to find a free slot where to put the new channel. */
131 for (i = 0; i < channels_alloc; i++) 132 for (found = -1, i = 0; i < channels_alloc; i++)
132 if (channels[i].type == SSH_CHANNEL_FREE) 133 if (channels[i].type == SSH_CHANNEL_FREE)
133 { 134 {
134 /* Found a free slot. Initialize the fields and return its number. */ 135 /* Found a free slot. */
135 buffer_init(&channels[i].input); 136 found = i;
136 buffer_init(&channels[i].output); 137 break;
137 channels[i].self = i;
138 channels[i].type = type;
139 channels[i].x11 = 0;
140 channels[i].sock = sock;
141 channels[i].remote_id = -1;
142 channels[i].remote_name = remote_name;
143 chan_init_iostates(&channels[i]);
144 return i;
145 } 138 }
146 139
147 /* There are no free slots. Must expand the array. */ 140 if (found == -1)
148 old_channels = channels_alloc; 141 {
149 channels_alloc += 10; 142 /* There are no free slots. Take last+1 slot and expand the array. */
150 channels = xrealloc(channels, channels_alloc * sizeof(Channel)); 143 found = channels_alloc;
151 for (i = old_channels; i < channels_alloc; i++) 144 channels_alloc += 10;
152 channels[i].type = SSH_CHANNEL_FREE; 145 debug("channel: expanding %d", channels_alloc);
153 146 channels = xrealloc(channels, channels_alloc * sizeof(Channel));
154 /* We know that the next one after the old maximum channel number is now 147 for (i = found; i < channels_alloc; i++)
155 available. Initialize and return its number. */ 148 channels[i].type = SSH_CHANNEL_FREE;
156 buffer_init(&channels[old_channels].input); 149 }
157 buffer_init(&channels[old_channels].output); 150
158 channels[old_channels].self = old_channels; 151 /* Initialize and return new channel number. */
159 channels[old_channels].type = type; 152 c=&channels[found];
160 channels[old_channels].x11 = 0; 153 buffer_init(&c->input);
161 channels[old_channels].sock = sock; 154 buffer_init(&c->output);
162 channels[old_channels].remote_id = -1; 155 chan_init_iostates(c);
163 channels[old_channels].remote_name = remote_name; 156 c->self = found;
164 chan_init_iostates(&channels[old_channels]); 157 c->type = type;
165 return old_channels; 158 c->x11 = 0;
159 c->sock = sock;
160 c->remote_id = -1;
161 c->remote_name = remote_name;
162 debug("channel %d: new [%s]", found, remote_name);
163 return found;
166} 164}
167 165
168/* Free the channel and close its socket. */ 166/* Free the channel and close its socket. */
@@ -336,10 +334,10 @@ void channel_prepare_select(fd_set *readset, fd_set *writeset)
336 packet_put_int(ch->remote_id); 334 packet_put_int(ch->remote_id);
337 packet_send(); 335 packet_send();
338 }else{ 336 }else{
339 debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); 337 debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate);
340 chan_read_failed(ch); 338 chan_read_failed(ch);
341 chan_write_failed(ch); 339 chan_write_failed(ch);
342 debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); 340 debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate);
343 } 341 }
344 break; 342 break;
345 343
@@ -407,9 +405,9 @@ void channel_after_select(fd_set *readset, fd_set *writeset)
407 break; 405 break;
408 } 406 }
409 remote_hostname = get_remote_hostname(newsock); 407 remote_hostname = get_remote_hostname(newsock);
410 snprintf(buf, sizeof buf, "port %d, connection from %.200s port %d", 408 snprintf(buf, sizeof buf, "listen port %d:%.100s:%d, connect from %.200s:%d",
411 ch->listening_port, remote_hostname, 409 ch->listening_port, ch->path, ch->host_port,
412 get_peer_port(newsock)); 410 remote_hostname, get_peer_port(newsock));
413 xfree(remote_hostname); 411 xfree(remote_hostname);
414 newch = channel_allocate(SSH_CHANNEL_OPENING, newsock, 412 newch = channel_allocate(SSH_CHANNEL_OPENING, newsock,
415 xstrdup(buf)); 413 xstrdup(buf));
@@ -830,8 +828,9 @@ char *channel_open_message()
830 case SSH_CHANNEL_X11_OPEN: 828 case SSH_CHANNEL_X11_OPEN:
831 case SSH_CHANNEL_INPUT_DRAINING: 829 case SSH_CHANNEL_INPUT_DRAINING:
832 case SSH_CHANNEL_OUTPUT_DRAINING: 830 case SSH_CHANNEL_OUTPUT_DRAINING:
833 snprintf(buf, sizeof buf, " #%d/%d %.300s\r\n", 831 snprintf(buf, sizeof buf, " #%d %.300s (t%d r%d i%d o%d)\r\n",
834 c->self,c->type,c->remote_name); 832 c->self,c->remote_name,
833 c->type,c->remote_id, c->istate,c->ostate);
835 buffer_append(&buffer, buf, strlen(buf)); 834 buffer_append(&buffer, buf, strlen(buf));
836 continue; 835 continue;
837 default: 836 default:
diff --git a/cipher.c b/cipher.c
index f6f9b001f..e611d6c71 100644
--- a/cipher.c
+++ b/cipher.c
@@ -13,7 +13,7 @@ Created: Wed Apr 19 17:41:39 1995 ylo
13 13
14#include "config.h" 14#include "config.h"
15#include "includes.h" 15#include "includes.h"
16RCSID("$Id: cipher.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 16RCSID("$Id: cipher.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
17 17
18#include "ssh.h" 18#include "ssh.h"
19#include "cipher.h" 19#include "cipher.h"
diff --git a/mpaux.c b/mpaux.c
index b79f781a0..e1b97a158 100644
--- a/mpaux.c
+++ b/mpaux.c
@@ -16,7 +16,7 @@ precision integers.
16 16
17#include "config.h" 17#include "config.h"
18#include "includes.h" 18#include "includes.h"
19RCSID("$Id: mpaux.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 19RCSID("$Id: mpaux.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
20 20
21#ifdef HAVE_OPENSSL 21#ifdef HAVE_OPENSSL
22#include <openssl/bn.h> 22#include <openssl/bn.h>
diff --git a/scp.c b/scp.c
index 6145fdebd..a592c2aea 100644
--- a/scp.c
+++ b/scp.c
@@ -42,11 +42,11 @@ and ssh has the necessary privileges.)
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE. 43 * SUCH DAMAGE.
44 * 44 *
45 * $Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $ 45 * $Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $
46 */ 46 */
47 47
48#include "includes.h" 48#include "includes.h"
49RCSID("$Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $"); 49RCSID("$Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
50 50
51#include "ssh.h" 51#include "ssh.h"
52#include "xmalloc.h" 52#include "xmalloc.h"
@@ -976,7 +976,7 @@ run_err(const char *fmt, ...)
976 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 976 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
977 * SUCH DAMAGE. 977 * SUCH DAMAGE.
978 * 978 *
979 * $Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $ 979 * $Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $
980 */ 980 */
981 981
982char * 982char *
@@ -1183,7 +1183,7 @@ progressmeter(int flag)
1183 " - stalled -"); 1183 " - stalled -");
1184 } else { 1184 } else {
1185 remaining = (int)(totalbytes / (statbytes / elapsed) - elapsed); 1185 remaining = (int)(totalbytes / (statbytes / elapsed) - elapsed);
1186 i = elapsed / 3600; 1186 i = remaining / 3600;
1187 if (i) 1187 if (i)
1188 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), 1188 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1189 "%2d:", i); 1189 "%2d:", i);
diff --git a/ssh-add.c b/ssh-add.c
index 5ac3c303a..2b4966d73 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -14,7 +14,7 @@ Adds an identity to the authentication server, or removes an identity.
14*/ 14*/
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$Id: ssh-add.c,v 1.1 1999/10/27 03:42:45 damien Exp $"); 17RCSID("$Id: ssh-add.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
18 18
19#include "rsa.h" 19#include "rsa.h"
20#include "ssh.h" 20#include "ssh.h"
@@ -22,11 +22,10 @@ RCSID("$Id: ssh-add.c,v 1.1 1999/10/27 03:42:45 damien Exp $");
22#include "authfd.h" 22#include "authfd.h"
23 23
24void 24void
25delete_file(const char *filename) 25delete_file(AuthenticationConnection *ac, const char *filename)
26{ 26{
27 RSA *key; 27 RSA *key;
28 char *comment; 28 char *comment;
29 AuthenticationConnection *ac;
30 29
31 key = RSA_new(); 30 key = RSA_new();
32 if (!load_public_key(filename, key, &comment)) 31 if (!load_public_key(filename, key, &comment))
@@ -35,55 +34,29 @@ delete_file(const char *filename)
35 return; 34 return;
36 } 35 }
37 36
38 /* Send the request to the authentication agent. */
39 ac = ssh_get_authentication_connection();
40 if (!ac)
41 {
42 fprintf(stderr,
43 "Could not open a connection to your authentication agent.\n");
44 RSA_free(key);
45 xfree(comment);
46 return;
47 }
48 if (ssh_remove_identity(ac, key)) 37 if (ssh_remove_identity(ac, key))
49 fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); 38 fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment);
50 else 39 else
51 fprintf(stderr, "Could not remove identity: %s\n", filename); 40 fprintf(stderr, "Could not remove identity: %s\n", filename);
52 RSA_free(key); 41 RSA_free(key);
53 xfree(comment); 42 xfree(comment);
54 ssh_close_authentication_connection(ac);
55} 43}
56 44
57void 45void
58delete_all() 46delete_all(AuthenticationConnection *ac)
59{ 47{
60 AuthenticationConnection *ac;
61
62 /* Get a connection to the agent. */
63 ac = ssh_get_authentication_connection();
64 if (!ac)
65 {
66 fprintf(stderr,
67 "Could not open a connection to your authentication agent.\n");
68 return;
69 }
70
71 /* Send a request to remove all identities. */ 48 /* Send a request to remove all identities. */
72 if (ssh_remove_all_identities(ac)) 49 if (ssh_remove_all_identities(ac))
73 fprintf(stderr, "All identities removed.\n"); 50 fprintf(stderr, "All identities removed.\n");
74 else 51 else
75 fprintf(stderr, "Failed to remove all identitities.\n"); 52 fprintf(stderr, "Failed to remove all identitities.\n");
76
77 /* Close the connection to the agent. */
78 ssh_close_authentication_connection(ac);
79} 53}
80 54
81void 55void
82add_file(const char *filename) 56add_file(AuthenticationConnection *ac, const char *filename)
83{ 57{
84 RSA *key; 58 RSA *key;
85 RSA *public_key; 59 RSA *public_key;
86 AuthenticationConnection *ac;
87 char *saved_comment, *comment, *pass; 60 char *saved_comment, *comment, *pass;
88 int first; 61 int first;
89 62
@@ -131,40 +104,22 @@ add_file(const char *filename)
131 104
132 xfree(saved_comment); 105 xfree(saved_comment);
133 106
134 /* Send the key to the authentication agent. */
135 ac = ssh_get_authentication_connection();
136 if (!ac)
137 {
138 fprintf(stderr,
139 "Could not open a connection to your authentication agent.\n");
140 RSA_free(key);
141 xfree(comment);
142 return;
143 }
144 if (ssh_add_identity(ac, key, comment)) 107 if (ssh_add_identity(ac, key, comment))
145 fprintf(stderr, "Identity added: %s (%s)\n", filename, comment); 108 fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
146 else 109 else
147 fprintf(stderr, "Could not add identity: %s\n", filename); 110 fprintf(stderr, "Could not add identity: %s\n", filename);
148 RSA_free(key); 111 RSA_free(key);
149 xfree(comment); 112 xfree(comment);
150 ssh_close_authentication_connection(ac);
151} 113}
152 114
153void 115void
154list_identities() 116list_identities(AuthenticationConnection *ac)
155{ 117{
156 AuthenticationConnection *ac;
157 BIGNUM *e, *n; 118 BIGNUM *e, *n;
158 int bits, status; 119 int bits, status;
159 char *comment; 120 char *comment;
160 int had_identities; 121 int had_identities;
161 122
162 ac = ssh_get_authentication_connection();
163 if (!ac)
164 {
165 fprintf(stderr, "Could not connect to authentication server.\n");
166 return;
167 }
168 e = BN_new(); 123 e = BN_new();
169 n = BN_new(); 124 n = BN_new();
170 had_identities = 0; 125 had_identities = 0;
@@ -189,12 +144,12 @@ list_identities()
189 BN_clear_free(n); 144 BN_clear_free(n);
190 if (!had_identities) 145 if (!had_identities)
191 printf("The agent has no identities.\n"); 146 printf("The agent has no identities.\n");
192 ssh_close_authentication_connection(ac);
193} 147}
194 148
195int 149int
196main(int ac, char **av) 150main(int argc, char **argv)
197{ 151{
152 AuthenticationConnection *ac = NULL;
198 struct passwd *pw; 153 struct passwd *pw;
199 char buf[1024]; 154 char buf[1024];
200 int no_files = 1; 155 int no_files = 1;
@@ -211,30 +166,37 @@ main(int ac, char **av)
211 exit(1); 166 exit(1);
212 } 167 }
213 168
214 for (i = 1; i < ac; i++) 169 /* At first, get a connection to the authentication agent. */
170 ac = ssh_get_authentication_connection();
171 if (ac == NULL) {
172 fprintf(stderr, "Could not open a connection to your authentication agent.\n");
173 exit(1);
174 }
175
176 for (i = 1; i < argc; i++)
215 { 177 {
216 if (strcmp(av[i], "-l") == 0) 178 if (strcmp(argv[i], "-l") == 0)
217 { 179 {
218 list_identities(); 180 list_identities(ac);
219 no_files = 0; /* Don't default-add/delete if -l. */ 181 no_files = 0; /* Don't default-add/delete if -l. */
220 continue; 182 continue;
221 } 183 }
222 if (strcmp(av[i], "-d") == 0) 184 if (strcmp(argv[i], "-d") == 0)
223 { 185 {
224 deleting = 1; 186 deleting = 1;
225 continue; 187 continue;
226 } 188 }
227 if (strcmp(av[i], "-D") == 0) 189 if (strcmp(argv[i], "-D") == 0)
228 { 190 {
229 delete_all(); 191 delete_all(ac);
230 no_files = 0; 192 no_files = 0;
231 continue; 193 continue;
232 } 194 }
233 no_files = 0; 195 no_files = 0;
234 if (deleting) 196 if (deleting)
235 delete_file(av[i]); 197 delete_file(ac, argv[i]);
236 else 198 else
237 add_file(av[i]); 199 add_file(ac, argv[i]);
238 } 200 }
239 if (no_files) 201 if (no_files)
240 { 202 {
@@ -242,13 +204,15 @@ main(int ac, char **av)
242 if (!pw) 204 if (!pw)
243 { 205 {
244 fprintf(stderr, "No user found with uid %d\n", (int)getuid()); 206 fprintf(stderr, "No user found with uid %d\n", (int)getuid());
207 ssh_close_authentication_connection(ac);
245 exit(1); 208 exit(1);
246 } 209 }
247 snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); 210 snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY);
248 if (deleting) 211 if (deleting)
249 delete_file(buf); 212 delete_file(ac, buf);
250 else 213 else
251 add_file(buf); 214 add_file(ac, buf);
252 } 215 }
216 ssh_close_authentication_connection(ac);
253 exit(0); 217 exit(0);
254} 218}
diff --git a/ssh-agent.c b/ssh-agent.c
index 562f3ccd9..56618aded 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -15,7 +15,7 @@ The authentication agent program.
15 15
16#include "config.h" 16#include "config.h"
17#include "includes.h" 17#include "includes.h"
18RCSID("$Id: ssh-agent.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 18RCSID("$Id: ssh-agent.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
19 19
20#include "ssh.h" 20#include "ssh.h"
21#include "rsa.h" 21#include "rsa.h"
@@ -536,6 +536,15 @@ main(int ac, char **av)
536 exit(1); 536 exit(1);
537 } 537 }
538 538
539 /* Create a new session and process group */
540 if (setsid() < 0) {
541 perror("setsid failed");
542 exit(1);
543 }
544
545 /* Ignore if a client dies while we are sending a reply */
546 signal(SIGPIPE, SIG_IGN);
547
539 sock = socket(AF_UNIX, SOCK_STREAM, 0); 548 sock = socket(AF_UNIX, SOCK_STREAM, 0);
540 if (sock < 0) 549 if (sock < 0)
541 { 550 {
diff --git a/ssh.c b/ssh.c
index 6846267e0..ed4ceaf43 100644
--- a/ssh.c
+++ b/ssh.c
@@ -18,7 +18,7 @@ Modified to work with SSL by Niels Provos <provos@citi.umich.edu> in Canada.
18*/ 18*/
19 19
20#include "includes.h" 20#include "includes.h"
21RCSID("$Id: ssh.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 21RCSID("$Id: ssh.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
22 22
23#include "xmalloc.h" 23#include "xmalloc.h"
24#include "ssh.h" 24#include "ssh.h"
@@ -158,8 +158,6 @@ rsh_connect(char *host, char *user, Buffer *command)
158 158
159/* Main program for the ssh client. */ 159/* Main program for the ssh client. */
160 160
161uid_t original_real_uid;
162
163int 161int
164main(int ac, char **av) 162main(int ac, char **av)
165{ 163{
diff --git a/sshconnect.c b/sshconnect.c
index 647dfbd8d..4222646d9 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -16,7 +16,7 @@ login (authentication) dialog.
16 16
17#include "config.h" 17#include "config.h"
18#include "includes.h" 18#include "includes.h"
19RCSID("$Id: sshconnect.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); 19RCSID("$Id: sshconnect.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
20 20
21#ifdef HAVE_OPENSSL 21#ifdef HAVE_OPENSSL
22#include <openssl/bn.h> 22#include <openssl/bn.h>