mirror of
https://github.com/clearml/dropbear
synced 2025-05-04 20:21:01 +00:00
- Split main socket var into ses.sock_in/ses.sock_out in preparation
for -J proxy_cmd option (and some prelim options for that) --HG-- extra : convert_revision : 47cdea9a7d66c553c6f5eec43b899821939d4e4c
This commit is contained in:
parent
460bf43822
commit
b619e88f54
18
cli-main.c
18
cli-main.c
@ -39,7 +39,7 @@ int cli_main(int argc, char ** argv) {
|
|||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int sock;
|
int sock_in, sock_out;
|
||||||
char* error = NULL;
|
char* error = NULL;
|
||||||
char* hostandport;
|
char* hostandport;
|
||||||
int len;
|
int len;
|
||||||
@ -58,10 +58,18 @@ int main(int argc, char ** argv) {
|
|||||||
dropbear_exit("signal() error");
|
dropbear_exit("signal() error");
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport,
|
#ifdef CLI_ENABLE_PROXYCMD
|
||||||
0, &error);
|
if (cli_runopts.proxycmd) {
|
||||||
|
|
||||||
if (sock < 0) {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport,
|
||||||
|
0, &error);
|
||||||
|
sock_in = sock_out = sock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock_in < 0) {
|
||||||
dropbear_exit("%s", error);
|
dropbear_exit("%s", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +80,7 @@ int main(int argc, char ** argv) {
|
|||||||
snprintf(hostandport, len, "%s:%s",
|
snprintf(hostandport, len, "%s:%s",
|
||||||
cli_opts.remotehost, cli_opts.remoteport);
|
cli_opts.remotehost, cli_opts.remoteport);
|
||||||
|
|
||||||
cli_session(sock, hostandport);
|
cli_session(sock_in, sock_out, hostandport);
|
||||||
|
|
||||||
/* not reached */
|
/* not reached */
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -65,6 +65,9 @@ static void printhelp() {
|
|||||||
#endif
|
#endif
|
||||||
"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
|
"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
|
||||||
"-K <keepalive> (0 is never, default %d)\n"
|
"-K <keepalive> (0 is never, default %d)\n"
|
||||||
|
#ifdef ENABLE_CLI_PROXYCMD
|
||||||
|
"-J <proxy_program> Use program rather than tcp connection"
|
||||||
|
#endif
|
||||||
#ifdef DEBUG_TRACE
|
#ifdef DEBUG_TRACE
|
||||||
"-v verbose\n"
|
"-v verbose\n"
|
||||||
#endif
|
#endif
|
||||||
@ -86,6 +89,9 @@ void cli_getopts(int argc, char ** argv) {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||||
int nextisremote = 0;
|
int nextisremote = 0;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_CLI_PROXYCMD
|
||||||
|
int nextisproxycmd = 0;
|
||||||
#endif
|
#endif
|
||||||
char* dummy = NULL; /* Not used for anything real */
|
char* dummy = NULL; /* Not used for anything real */
|
||||||
|
|
||||||
@ -198,6 +204,11 @@ void cli_getopts(int argc, char ** argv) {
|
|||||||
case 'R':
|
case 'R':
|
||||||
nextisremote = 1;
|
nextisremote = 1;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_CLI_PROXYCMD
|
||||||
|
case 'J':
|
||||||
|
next = &cli_opts.proxycmd;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'l':
|
case 'l':
|
||||||
next = &cli_opts.username;
|
next = &cli_opts.username;
|
||||||
|
@ -74,13 +74,13 @@ static const struct ChanType *cli_chantypes[] = {
|
|||||||
NULL /* Null termination */
|
NULL /* Null termination */
|
||||||
};
|
};
|
||||||
|
|
||||||
void cli_session(int sock, char* remotehost) {
|
void cli_session(int sock_in, int sock_out, char* remotehost) {
|
||||||
|
|
||||||
seedrandom();
|
seedrandom();
|
||||||
|
|
||||||
crypto_init();
|
crypto_init();
|
||||||
|
|
||||||
common_session_init(sock, remotehost);
|
common_session_init(sock_in, sock_out, remotehost);
|
||||||
|
|
||||||
chaninitialise(cli_chantypes);
|
chaninitialise(cli_chantypes);
|
||||||
|
|
||||||
@ -294,8 +294,10 @@ static void cli_remoteclosed() {
|
|||||||
|
|
||||||
/* XXX TODO perhaps print a friendlier message if we get this but have
|
/* XXX TODO perhaps print a friendlier message if we get this but have
|
||||||
* already sent/received disconnect message(s) ??? */
|
* already sent/received disconnect message(s) ??? */
|
||||||
close(ses.sock);
|
m_close(ses.sock_in);
|
||||||
ses.sock = -1;
|
m_close(ses.sock_out);
|
||||||
|
ses.sock_in = -1;
|
||||||
|
ses.sock_out = -1;
|
||||||
dropbear_exit("remote closed the connection");
|
dropbear_exit("remote closed the connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,14 +52,15 @@ int exitflag = 0; /* GLOBAL */
|
|||||||
|
|
||||||
|
|
||||||
/* called only at the start of a session, set up initial state */
|
/* called only at the start of a session, set up initial state */
|
||||||
void common_session_init(int sock, char* remotehost) {
|
void common_session_init(int sock_in, int sock_out, char* remotehost) {
|
||||||
|
|
||||||
TRACE(("enter session_init"))
|
TRACE(("enter session_init"))
|
||||||
|
|
||||||
ses.remotehost = remotehost;
|
ses.remotehost = remotehost;
|
||||||
|
|
||||||
ses.sock = sock;
|
ses.sock_in = sock_in;
|
||||||
ses.maxfd = sock;
|
ses.sock_out = sock_out;
|
||||||
|
ses.maxfd = MAX(sock_in, sock_out);
|
||||||
|
|
||||||
ses.connect_time = 0;
|
ses.connect_time = 0;
|
||||||
ses.last_packet_time = 0;
|
ses.last_packet_time = 0;
|
||||||
@ -137,11 +138,11 @@ void session_loop(void(*loophandler)()) {
|
|||||||
FD_ZERO(&writefd);
|
FD_ZERO(&writefd);
|
||||||
FD_ZERO(&readfd);
|
FD_ZERO(&readfd);
|
||||||
dropbear_assert(ses.payload == NULL);
|
dropbear_assert(ses.payload == NULL);
|
||||||
if (ses.sock != -1) {
|
if (ses.sock_in != -1) {
|
||||||
FD_SET(ses.sock, &readfd);
|
FD_SET(ses.sock_in, &readfd);
|
||||||
if (!isempty(&ses.writequeue)) {
|
|
||||||
FD_SET(ses.sock, &writefd);
|
|
||||||
}
|
}
|
||||||
|
if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
|
||||||
|
FD_SET(ses.sock_out, &writefd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We get woken up when signal handlers write to this pipe.
|
/* We get woken up when signal handlers write to this pipe.
|
||||||
@ -183,12 +184,14 @@ void session_loop(void(*loophandler)()) {
|
|||||||
checktimeouts();
|
checktimeouts();
|
||||||
|
|
||||||
/* process session socket's incoming/outgoing data */
|
/* process session socket's incoming/outgoing data */
|
||||||
if (ses.sock != -1) {
|
if (ses.sock_out != -1) {
|
||||||
if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) {
|
if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) {
|
||||||
write_packet();
|
write_packet();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (FD_ISSET(ses.sock, &readfd)) {
|
if (ses.sock_in != -1) {
|
||||||
|
if (FD_ISSET(ses.sock_in, &readfd)) {
|
||||||
read_packet();
|
read_packet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,14 +251,14 @@ void session_identification() {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* write our version string, this blocks */
|
/* write our version string, this blocks */
|
||||||
if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
|
if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n",
|
||||||
strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
|
strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
|
||||||
ses.remoteclosed();
|
ses.remoteclosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If they send more than 50 lines, something is wrong */
|
/* If they send more than 50 lines, something is wrong */
|
||||||
for (i = 0; i < 50; i++) {
|
for (i = 0; i < 50; i++) {
|
||||||
len = ident_readln(ses.sock, linebuf, sizeof(linebuf));
|
len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
|
||||||
|
|
||||||
if (len < 0 && errno != EINTR) {
|
if (len < 0 && errno != EINTR) {
|
||||||
/* It failed */
|
/* It failed */
|
||||||
|
@ -60,6 +60,10 @@ etc) slower (perhaps by 50%). Recommended for most small systems. */
|
|||||||
#define ENABLE_CLI_LOCALTCPFWD
|
#define ENABLE_CLI_LOCALTCPFWD
|
||||||
#define ENABLE_CLI_REMOTETCPFWD
|
#define ENABLE_CLI_REMOTETCPFWD
|
||||||
|
|
||||||
|
/* Allow using -J <proxycommand> to run the connection through a
|
||||||
|
pipe to a program, rather the normal TCP connection */
|
||||||
|
/*#define ENABLE_CLI_PROXYCMD*/
|
||||||
|
|
||||||
#define ENABLE_SVR_LOCALTCPFWD
|
#define ENABLE_SVR_LOCALTCPFWD
|
||||||
#define ENABLE_SVR_REMOTETCPFWD
|
#define ENABLE_SVR_REMOTETCPFWD
|
||||||
|
|
||||||
|
6
packet.c
6
packet.c
@ -61,7 +61,7 @@ void write_packet() {
|
|||||||
len = writebuf->len - writebuf->pos;
|
len = writebuf->len - writebuf->pos;
|
||||||
dropbear_assert(len > 0);
|
dropbear_assert(len > 0);
|
||||||
/* Try to write as much as possible */
|
/* Try to write as much as possible */
|
||||||
written = write(ses.sock, buf_getptr(writebuf, len), len);
|
written = write(ses.sock_out, buf_getptr(writebuf, len), len);
|
||||||
|
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
@ -122,7 +122,7 @@ void read_packet() {
|
|||||||
* mightn't be any available (EAGAIN) */
|
* mightn't be any available (EAGAIN) */
|
||||||
dropbear_assert(ses.readbuf != NULL);
|
dropbear_assert(ses.readbuf != NULL);
|
||||||
maxlen = ses.readbuf->len - ses.readbuf->pos;
|
maxlen = ses.readbuf->len - ses.readbuf->pos;
|
||||||
len = read(ses.sock, buf_getptr(ses.readbuf, maxlen), maxlen);
|
len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen);
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
ses.remoteclosed();
|
ses.remoteclosed();
|
||||||
@ -171,7 +171,7 @@ static void read_packet_init() {
|
|||||||
maxlen = blocksize - ses.readbuf->pos;
|
maxlen = blocksize - ses.readbuf->pos;
|
||||||
|
|
||||||
/* read the rest of the packet if possible */
|
/* read the rest of the packet if possible */
|
||||||
len = read(ses.sock, buf_getwriteptr(ses.readbuf, maxlen),
|
len = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen),
|
||||||
maxlen);
|
maxlen);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
ses.remoteclosed();
|
ses.remoteclosed();
|
||||||
|
@ -117,6 +117,9 @@ typedef struct cli_runopts {
|
|||||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||||
struct TCPFwdList * localfwds;
|
struct TCPFwdList * localfwds;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENABLE_CLI_PROXYCMD
|
||||||
|
char *proxycmd;
|
||||||
|
#endif
|
||||||
|
|
||||||
} cli_runopts;
|
} cli_runopts;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
extern int sessinitdone; /* Is set to 0 somewhere */
|
extern int sessinitdone; /* Is set to 0 somewhere */
|
||||||
extern int exitflag;
|
extern int exitflag;
|
||||||
|
|
||||||
void common_session_init(int sock, char* remotehost);
|
void common_session_init(int sock_in, int sock_out, char* remotehost);
|
||||||
void session_loop(void(*loophandler)());
|
void session_loop(void(*loophandler)());
|
||||||
void common_session_cleanup();
|
void common_session_cleanup();
|
||||||
void session_identification();
|
void session_identification();
|
||||||
@ -54,7 +54,7 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param);
|
|||||||
void svr_dropbear_log(int priority, const char* format, va_list param);
|
void svr_dropbear_log(int priority, const char* format, va_list param);
|
||||||
|
|
||||||
/* Client */
|
/* Client */
|
||||||
void cli_session(int sock, char *remotehost);
|
void cli_session(int sock_in, int sock_out, char *remotehost);
|
||||||
void cli_session_cleanup();
|
void cli_session_cleanup();
|
||||||
void cleantext(unsigned char* dirtytext);
|
void cleantext(unsigned char* dirtytext);
|
||||||
|
|
||||||
@ -97,7 +97,8 @@ struct sshsession {
|
|||||||
(cleared after auth once we're not
|
(cleared after auth once we're not
|
||||||
respecting AUTH_TIMEOUT any more) */
|
respecting AUTH_TIMEOUT any more) */
|
||||||
|
|
||||||
int sock;
|
int sock_in;
|
||||||
|
int sock_out;
|
||||||
|
|
||||||
unsigned char *remotehost; /* the peer hostname */
|
unsigned char *remotehost; /* the peer hostname */
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ void svr_session(int sock, int childpipe,
|
|||||||
reseedrandom();
|
reseedrandom();
|
||||||
|
|
||||||
crypto_init();
|
crypto_init();
|
||||||
common_session_init(sock, remotehost);
|
common_session_init(sock, sock, remotehost);
|
||||||
|
|
||||||
/* Initialise server specific parts of the session */
|
/* Initialise server specific parts of the session */
|
||||||
svr_ses.childpipe = childpipe;
|
svr_ses.childpipe = childpipe;
|
||||||
@ -183,7 +183,7 @@ void svr_dropbear_log(int priority, const char* format, va_list param) {
|
|||||||
localtime(×ec)) == 0)
|
localtime(×ec)) == 0)
|
||||||
{
|
{
|
||||||
/* upon failure, just print the epoch-seconds time. */
|
/* upon failure, just print the epoch-seconds time. */
|
||||||
snprintf(datestr, sizeof(datestr), "%d", timesec);
|
snprintf(datestr, sizeof(datestr), "%d", (int)timesec);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf);
|
fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf);
|
||||||
}
|
}
|
||||||
@ -192,8 +192,10 @@ void svr_dropbear_log(int priority, const char* format, va_list param) {
|
|||||||
/* called when the remote side closes the connection */
|
/* called when the remote side closes the connection */
|
||||||
static void svr_remoteclosed() {
|
static void svr_remoteclosed() {
|
||||||
|
|
||||||
close(ses.sock);
|
m_close(ses.sock_in);
|
||||||
ses.sock = -1;
|
m_close(ses.sock_out);
|
||||||
|
ses.sock_in = -1;
|
||||||
|
ses.sock_out = -1;
|
||||||
dropbear_close("Exited normally");
|
dropbear_close("Exited normally");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user