*/
#include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.255 2005/12/06 22:38:27 reyk Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.261 2006/02/12 06:45:34 djm Exp $");
+
+#include <sys/resource.h>
+#include <sys/ioctl.h>
+
+#include <paths.h>
#include <openssl/evp.h>
#include <openssl/err.h>
" [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
" [-w tunnel:tunnel] [user@]hostname [command]\n"
);
- exit(1);
+ exit(255);
}
static int ssh_session(void);
pw = getpwuid(original_real_uid);
if (!pw) {
logit("You don't exist, go away!");
- exit(1);
+ exit(255);
}
/* Take a copy of the returned structure. */
pw = pwcopy(pw);
exit(0);
break;
case 'w':
- options.tun_open = 1;
+ if (options.tun_open == -1)
+ options.tun_open = SSH_TUNMODE_DEFAULT;
options.tun_local = a2tun(optarg, &options.tun_remote);
- if (options.tun_local < -1) {
+ if (options.tun_local == SSH_TUNID_ERR) {
fprintf(stderr, "Bad tun device '%s'\n", optarg);
- exit(1);
+ exit(255);
}
break;
case 'q':
else {
fprintf(stderr, "Bad escape character '%s'.\n",
optarg);
- exit(1);
+ exit(255);
}
break;
case 'c':
fprintf(stderr,
"Unknown cipher type '%s'\n",
optarg);
- exit(1);
+ exit(255);
}
if (options.cipher == SSH_CIPHER_3DES)
options.ciphers = "3des-cbc";
else {
fprintf(stderr, "Unknown mac type '%s'\n",
optarg);
- exit(1);
+ exit(255);
}
break;
case 'M':
options.port = a2port(optarg);
if (options.port == 0) {
fprintf(stderr, "Bad port '%s'\n", optarg);
- exit(1);
+ exit(255);
}
break;
case 'l':
fprintf(stderr,
"Bad local forwarding specification '%s'\n",
optarg);
- exit(1);
+ exit(255);
}
break;
fprintf(stderr,
"Bad remote forwarding specification "
"'%s'\n", optarg);
- exit(1);
+ exit(255);
}
break;
if ((fwd.listen_host = hpdelim(&cp)) == NULL) {
fprintf(stderr, "Bad dynamic forwarding "
"specification '%.100s'\n", optarg);
- exit(1);
+ exit(255);
}
if (cp != NULL) {
fwd.listen_port = a2port(cp);
if (fwd.listen_port == 0) {
fprintf(stderr, "Bad dynamic port '%s'\n",
optarg);
- exit(1);
+ exit(255);
}
add_local_forward(&options, &fwd);
xfree(p);
line = xstrdup(optarg);
if (process_config_line(&options, host ? host : "",
line, "command-line", 0, &dummy) != 0)
- exit(1);
+ exit(255);
xfree(line);
break;
case 's':
options.control_path = NULL;
if (options.control_path != NULL) {
+ char me[NI_MAXHOST];
+
+ if (gethostname(me, sizeof(me)) == -1)
+ fatal("gethostname: %s", strerror(errno));
snprintf(buf, sizeof(buf), "%d", options.port);
cp = tilde_expand_filename(options.control_path,
original_real_uid);
options.control_path = percent_expand(cp, "p", buf, "h", host,
- "r", options.user, (char *)NULL);
+ "r", options.user, "l", me, (char *)NULL);
xfree(cp);
}
if (mux_command != 0 && options.control_path == NULL)
original_effective_uid == 0 && options.use_privileged_port,
#endif
options.proxy_command) != 0)
- exit(1);
+ exit(255);
/*
* If we successfully made the connection, load the host private key
packet_send();
}
- if (options.tun_open) {
+ if (options.tun_open != SSH_TUNMODE_NO) {
Channel *c;
int fd;
debug("Requesting tun.");
- if ((fd = tun_open(options.tun_local)) >= 0) {
+ if ((fd = tun_open(options.tun_local,
+ options.tun_open)) >= 0) {
c = channel_new("tun", SSH_CHANNEL_OPENING, fd, fd, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
0, "tun", 1);
c->datagram = 1;
+#if defined(SSH_TUN_FILTER)
+ if (options.tun_open == SSH_TUNMODE_POINTOPOINT)
+ channel_register_filter(c->self, sys_tun_infilter,
+ sys_tun_outfilter);
+#endif
packet_start(SSH2_MSG_CHANNEL_OPEN);
packet_put_cstring("tun@openssh.com");
packet_put_int(c->self);
packet_put_int(c->local_window_max);
packet_put_int(c->local_maxpacket);
+ packet_put_int(options.tun_open);
packet_put_int(options.tun_remote);
packet_send();
}