Merged latest OpenBSD changes.

This commit is contained in:
Damien Miller 1999-10-28 15:23:30 +10:00
parent 29d685212f
commit 01ab4a25c8
9 changed files with 83 additions and 113 deletions

View File

@ -17,7 +17,7 @@ validity of the host key.
#include "config.h" #include "config.h"
#include "includes.h" #include "includes.h"
RCSID("$Id: auth-rsa.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: auth-rsa.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#include "rsa.h" #include "rsa.h"
#include "packet.h" #include "packet.h"

View File

@ -16,7 +16,7 @@ arbitrary tcp/ip connections, and the authentication agent connection.
*/ */
#include "includes.h" #include "includes.h"
RCSID("$Id: channels.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); RCSID("$Id: channels.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
#include "ssh.h" #include "ssh.h"
#include "packet.h" #include "packet.h"
@ -108,7 +108,8 @@ void channel_permit_all_opens()
int channel_allocate(int type, int sock, char *remote_name) int channel_allocate(int type, int sock, char *remote_name)
{ {
int i, old_channels; int i, found;
Channel *c;
/* Update the maximum file descriptor value. */ /* Update the maximum file descriptor value. */
if (sock > channel_max_fd_value) if (sock > channel_max_fd_value)
@ -128,41 +129,38 @@ int channel_allocate(int type, int sock, char *remote_name)
} }
/* Try to find a free slot where to put the new channel. */ /* Try to find a free slot where to put the new channel. */
for (i = 0; i < channels_alloc; i++) for (found = -1, i = 0; i < channels_alloc; i++)
if (channels[i].type == SSH_CHANNEL_FREE) if (channels[i].type == SSH_CHANNEL_FREE)
{ {
/* Found a free slot. Initialize the fields and return its number. */ /* Found a free slot. */
buffer_init(&channels[i].input); found = i;
buffer_init(&channels[i].output); break;
channels[i].self = i;
channels[i].type = type;
channels[i].x11 = 0;
channels[i].sock = sock;
channels[i].remote_id = -1;
channels[i].remote_name = remote_name;
chan_init_iostates(&channels[i]);
return i;
} }
/* There are no free slots. Must expand the array. */ if (found == -1)
old_channels = channels_alloc; {
/* There are no free slots. Take last+1 slot and expand the array. */
found = channels_alloc;
channels_alloc += 10; channels_alloc += 10;
debug("channel: expanding %d", channels_alloc);
channels = xrealloc(channels, channels_alloc * sizeof(Channel)); channels = xrealloc(channels, channels_alloc * sizeof(Channel));
for (i = old_channels; i < channels_alloc; i++) for (i = found; i < channels_alloc; i++)
channels[i].type = SSH_CHANNEL_FREE; channels[i].type = SSH_CHANNEL_FREE;
}
/* We know that the next one after the old maximum channel number is now /* Initialize and return new channel number. */
available. Initialize and return its number. */ c=&channels[found];
buffer_init(&channels[old_channels].input); buffer_init(&c->input);
buffer_init(&channels[old_channels].output); buffer_init(&c->output);
channels[old_channels].self = old_channels; chan_init_iostates(c);
channels[old_channels].type = type; c->self = found;
channels[old_channels].x11 = 0; c->type = type;
channels[old_channels].sock = sock; c->x11 = 0;
channels[old_channels].remote_id = -1; c->sock = sock;
channels[old_channels].remote_name = remote_name; c->remote_id = -1;
chan_init_iostates(&channels[old_channels]); c->remote_name = remote_name;
return old_channels; debug("channel %d: new [%s]", found, remote_name);
return found;
} }
/* Free the channel and close its socket. */ /* Free the channel and close its socket. */
@ -336,10 +334,10 @@ void channel_prepare_select(fd_set *readset, fd_set *writeset)
packet_put_int(ch->remote_id); packet_put_int(ch->remote_id);
packet_send(); packet_send();
}else{ }else{
debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate);
chan_read_failed(ch); chan_read_failed(ch);
chan_write_failed(ch); chan_write_failed(ch);
debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate);
} }
break; break;
@ -407,9 +405,9 @@ void channel_after_select(fd_set *readset, fd_set *writeset)
break; break;
} }
remote_hostname = get_remote_hostname(newsock); remote_hostname = get_remote_hostname(newsock);
snprintf(buf, sizeof buf, "port %d, connection from %.200s port %d", snprintf(buf, sizeof buf, "listen port %d:%.100s:%d, connect from %.200s:%d",
ch->listening_port, remote_hostname, ch->listening_port, ch->path, ch->host_port,
get_peer_port(newsock)); remote_hostname, get_peer_port(newsock));
xfree(remote_hostname); xfree(remote_hostname);
newch = channel_allocate(SSH_CHANNEL_OPENING, newsock, newch = channel_allocate(SSH_CHANNEL_OPENING, newsock,
xstrdup(buf)); xstrdup(buf));
@ -830,8 +828,9 @@ char *channel_open_message()
case SSH_CHANNEL_X11_OPEN: case SSH_CHANNEL_X11_OPEN:
case SSH_CHANNEL_INPUT_DRAINING: case SSH_CHANNEL_INPUT_DRAINING:
case SSH_CHANNEL_OUTPUT_DRAINING: case SSH_CHANNEL_OUTPUT_DRAINING:
snprintf(buf, sizeof buf, " #%d/%d %.300s\r\n", snprintf(buf, sizeof buf, " #%d %.300s (t%d r%d i%d o%d)\r\n",
c->self,c->type,c->remote_name); c->self,c->remote_name,
c->type,c->remote_id, c->istate,c->ostate);
buffer_append(&buffer, buf, strlen(buf)); buffer_append(&buffer, buf, strlen(buf));
continue; continue;
default: default:

View File

@ -13,7 +13,7 @@ Created: Wed Apr 19 17:41:39 1995 ylo
#include "config.h" #include "config.h"
#include "includes.h" #include "includes.h"
RCSID("$Id: cipher.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: cipher.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#include "ssh.h" #include "ssh.h"
#include "cipher.h" #include "cipher.h"

View File

@ -16,7 +16,7 @@ precision integers.
#include "config.h" #include "config.h"
#include "includes.h" #include "includes.h"
RCSID("$Id: mpaux.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: mpaux.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
#include <openssl/bn.h> #include <openssl/bn.h>

8
scp.c
View File

@ -42,11 +42,11 @@ and ssh has the necessary privileges.)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $ * $Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $
*/ */
#include "includes.h" #include "includes.h"
RCSID("$Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $"); RCSID("$Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
#include "ssh.h" #include "ssh.h"
#include "xmalloc.h" #include "xmalloc.h"
@ -976,7 +976,7 @@ run_err(const char *fmt, ...)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: scp.c,v 1.1 1999/10/27 03:42:45 damien Exp $ * $Id: scp.c,v 1.2 1999/10/28 05:23:30 damien Exp $
*/ */
char * char *
@ -1183,7 +1183,7 @@ progressmeter(int flag)
" - stalled -"); " - stalled -");
} else { } else {
remaining = (int)(totalbytes / (statbytes / elapsed) - elapsed); remaining = (int)(totalbytes / (statbytes / elapsed) - elapsed);
i = elapsed / 3600; i = remaining / 3600;
if (i) if (i)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
"%2d:", i); "%2d:", i);

View File

@ -14,7 +14,7 @@ Adds an identity to the authentication server, or removes an identity.
*/ */
#include "includes.h" #include "includes.h"
RCSID("$Id: ssh-add.c,v 1.1 1999/10/27 03:42:45 damien Exp $"); RCSID("$Id: ssh-add.c,v 1.2 1999/10/28 05:23:30 damien Exp $");
#include "rsa.h" #include "rsa.h"
#include "ssh.h" #include "ssh.h"
@ -22,11 +22,10 @@ RCSID("$Id: ssh-add.c,v 1.1 1999/10/27 03:42:45 damien Exp $");
#include "authfd.h" #include "authfd.h"
void void
delete_file(const char *filename) delete_file(AuthenticationConnection *ac, const char *filename)
{ {
RSA *key; RSA *key;
char *comment; char *comment;
AuthenticationConnection *ac;
key = RSA_new(); key = RSA_new();
if (!load_public_key(filename, key, &comment)) if (!load_public_key(filename, key, &comment))
@ -35,55 +34,29 @@ delete_file(const char *filename)
return; return;
} }
/* Send the request to the authentication agent. */
ac = ssh_get_authentication_connection();
if (!ac)
{
fprintf(stderr,
"Could not open a connection to your authentication agent.\n");
RSA_free(key);
xfree(comment);
return;
}
if (ssh_remove_identity(ac, key)) if (ssh_remove_identity(ac, key))
fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment);
else else
fprintf(stderr, "Could not remove identity: %s\n", filename); fprintf(stderr, "Could not remove identity: %s\n", filename);
RSA_free(key); RSA_free(key);
xfree(comment); xfree(comment);
ssh_close_authentication_connection(ac);
} }
void void
delete_all() delete_all(AuthenticationConnection *ac)
{ {
AuthenticationConnection *ac;
/* Get a connection to the agent. */
ac = ssh_get_authentication_connection();
if (!ac)
{
fprintf(stderr,
"Could not open a connection to your authentication agent.\n");
return;
}
/* Send a request to remove all identities. */ /* Send a request to remove all identities. */
if (ssh_remove_all_identities(ac)) if (ssh_remove_all_identities(ac))
fprintf(stderr, "All identities removed.\n"); fprintf(stderr, "All identities removed.\n");
else else
fprintf(stderr, "Failed to remove all identitities.\n"); fprintf(stderr, "Failed to remove all identitities.\n");
/* Close the connection to the agent. */
ssh_close_authentication_connection(ac);
} }
void void
add_file(const char *filename) add_file(AuthenticationConnection *ac, const char *filename)
{ {
RSA *key; RSA *key;
RSA *public_key; RSA *public_key;
AuthenticationConnection *ac;
char *saved_comment, *comment, *pass; char *saved_comment, *comment, *pass;
int first; int first;
@ -131,40 +104,22 @@ add_file(const char *filename)
xfree(saved_comment); xfree(saved_comment);
/* Send the key to the authentication agent. */
ac = ssh_get_authentication_connection();
if (!ac)
{
fprintf(stderr,
"Could not open a connection to your authentication agent.\n");
RSA_free(key);
xfree(comment);
return;
}
if (ssh_add_identity(ac, key, comment)) if (ssh_add_identity(ac, key, comment))
fprintf(stderr, "Identity added: %s (%s)\n", filename, comment); fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
else else
fprintf(stderr, "Could not add identity: %s\n", filename); fprintf(stderr, "Could not add identity: %s\n", filename);
RSA_free(key); RSA_free(key);
xfree(comment); xfree(comment);
ssh_close_authentication_connection(ac);
} }
void void
list_identities() list_identities(AuthenticationConnection *ac)
{ {
AuthenticationConnection *ac;
BIGNUM *e, *n; BIGNUM *e, *n;
int bits, status; int bits, status;
char *comment; char *comment;
int had_identities; int had_identities;
ac = ssh_get_authentication_connection();
if (!ac)
{
fprintf(stderr, "Could not connect to authentication server.\n");
return;
}
e = BN_new(); e = BN_new();
n = BN_new(); n = BN_new();
had_identities = 0; had_identities = 0;
@ -189,12 +144,12 @@ list_identities()
BN_clear_free(n); BN_clear_free(n);
if (!had_identities) if (!had_identities)
printf("The agent has no identities.\n"); printf("The agent has no identities.\n");
ssh_close_authentication_connection(ac);
} }
int int
main(int ac, char **av) main(int argc, char **argv)
{ {
AuthenticationConnection *ac = NULL;
struct passwd *pw; struct passwd *pw;
char buf[1024]; char buf[1024];
int no_files = 1; int no_files = 1;
@ -211,30 +166,37 @@ main(int ac, char **av)
exit(1); exit(1);
} }
for (i = 1; i < ac; i++) /* At first, get a connection to the authentication agent. */
ac = ssh_get_authentication_connection();
if (ac == NULL) {
fprintf(stderr, "Could not open a connection to your authentication agent.\n");
exit(1);
}
for (i = 1; i < argc; i++)
{ {
if (strcmp(av[i], "-l") == 0) if (strcmp(argv[i], "-l") == 0)
{ {
list_identities(); list_identities(ac);
no_files = 0; /* Don't default-add/delete if -l. */ no_files = 0; /* Don't default-add/delete if -l. */
continue; continue;
} }
if (strcmp(av[i], "-d") == 0) if (strcmp(argv[i], "-d") == 0)
{ {
deleting = 1; deleting = 1;
continue; continue;
} }
if (strcmp(av[i], "-D") == 0) if (strcmp(argv[i], "-D") == 0)
{ {
delete_all(); delete_all(ac);
no_files = 0; no_files = 0;
continue; continue;
} }
no_files = 0; no_files = 0;
if (deleting) if (deleting)
delete_file(av[i]); delete_file(ac, argv[i]);
else else
add_file(av[i]); add_file(ac, argv[i]);
} }
if (no_files) if (no_files)
{ {
@ -242,13 +204,15 @@ main(int ac, char **av)
if (!pw) if (!pw)
{ {
fprintf(stderr, "No user found with uid %d\n", (int)getuid()); fprintf(stderr, "No user found with uid %d\n", (int)getuid());
ssh_close_authentication_connection(ac);
exit(1); exit(1);
} }
snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY); snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY);
if (deleting) if (deleting)
delete_file(buf); delete_file(ac, buf);
else else
add_file(buf); add_file(ac, buf);
} }
ssh_close_authentication_connection(ac);
exit(0); exit(0);
} }

View File

@ -15,7 +15,7 @@ The authentication agent program.
#include "config.h" #include "config.h"
#include "includes.h" #include "includes.h"
RCSID("$Id: ssh-agent.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: ssh-agent.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#include "ssh.h" #include "ssh.h"
#include "rsa.h" #include "rsa.h"
@ -536,6 +536,15 @@ main(int ac, char **av)
exit(1); exit(1);
} }
/* Create a new session and process group */
if (setsid() < 0) {
perror("setsid failed");
exit(1);
}
/* Ignore if a client dies while we are sending a reply */
signal(SIGPIPE, SIG_IGN);
sock = socket(AF_UNIX, SOCK_STREAM, 0); sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) if (sock < 0)
{ {

4
ssh.c
View File

@ -18,7 +18,7 @@ Modified to work with SSL by Niels Provos <provos@citi.umich.edu> in Canada.
*/ */
#include "includes.h" #include "includes.h"
RCSID("$Id: ssh.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: ssh.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#include "xmalloc.h" #include "xmalloc.h"
#include "ssh.h" #include "ssh.h"
@ -158,8 +158,6 @@ rsh_connect(char *host, char *user, Buffer *command)
/* Main program for the ssh client. */ /* Main program for the ssh client. */
uid_t original_real_uid;
int int
main(int ac, char **av) main(int ac, char **av)
{ {

View File

@ -16,7 +16,7 @@ login (authentication) dialog.
#include "config.h" #include "config.h"
#include "includes.h" #include "includes.h"
RCSID("$Id: sshconnect.c,v 1.2 1999/10/28 03:25:17 damien Exp $"); RCSID("$Id: sshconnect.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
#include <openssl/bn.h> #include <openssl/bn.h>