mirror of
https://github.com/clearml/dropbear
synced 2025-03-03 10:41:39 +00:00
Combine code for SSH_CONNECTION and SSH_CLIENT
This commit is contained in:
parent
444b15889f
commit
776d908703
@ -51,10 +51,10 @@ struct ChanSess {
|
|||||||
/* exit details */
|
/* exit details */
|
||||||
struct exitinfo exit;
|
struct exitinfo exit;
|
||||||
|
|
||||||
/* Used to set $SSH_CONNECTION in the child session.
|
|
||||||
Is only set temporarily before forking */
|
|
||||||
char *connection_string;
|
|
||||||
|
|
||||||
|
/* These are only set temporarily before forking */
|
||||||
|
/* Used to set $SSH_CONNECTION in the child session. */
|
||||||
|
char *connection_string;
|
||||||
/* Used to set $SSH_CLIENT in the child session. */
|
/* Used to set $SSH_CLIENT in the child session. */
|
||||||
char *client_string;
|
char *client_string;
|
||||||
|
|
||||||
|
@ -603,34 +603,26 @@ static int sessionpty(struct ChanSess * chansess) {
|
|||||||
return DROPBEAR_SUCCESS;
|
return DROPBEAR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* make_connection_string() {
|
static void make_connection_string(struct ChanSess *chansess) {
|
||||||
char *local_ip, *local_port, *remote_ip, *remote_port;
|
char *local_ip, *local_port, *remote_ip, *remote_port;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *ret;
|
|
||||||
get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
|
get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
|
||||||
len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4;
|
|
||||||
ret = m_malloc(len);
|
|
||||||
snprintf(ret, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
|
|
||||||
m_free(local_ip);
|
|
||||||
m_free(local_port);
|
|
||||||
m_free(remote_ip);
|
|
||||||
m_free(remote_port);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* make_client_string() {
|
/* "remoteip remoteport localip localport" */
|
||||||
char *local_ip, *local_port, *remote_ip, *remote_port;
|
len = strlen(local_ip) + strlen(remote_ip) + 20;
|
||||||
size_t len;
|
chansess->connection_string = m_malloc(len);
|
||||||
char *ret;
|
snprintf(chansess->connection_string, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
|
||||||
get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
|
|
||||||
len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4;
|
/* deprecated but bash only loads .bashrc if SSH_CLIENT is set */
|
||||||
ret = m_malloc(len);
|
/* "remoteip remoteport localport" */
|
||||||
snprintf(ret, len, "%s %s %s", remote_ip, remote_port, local_port);
|
len = strlen(remote_ip) + 20;
|
||||||
|
chansess->client_string = m_malloc(len);
|
||||||
|
snprintf(chansess->client_string, len, "%s %s %s", remote_ip, remote_port, local_port);
|
||||||
|
|
||||||
m_free(local_ip);
|
m_free(local_ip);
|
||||||
m_free(local_port);
|
m_free(local_port);
|
||||||
m_free(remote_ip);
|
m_free(remote_ip);
|
||||||
m_free(remote_port);
|
m_free(remote_port);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle a command request from the client. This is used for both shell
|
/* Handle a command request from the client. This is used for both shell
|
||||||
@ -693,8 +685,7 @@ static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
|
|||||||
/* uClinux will vfork(), so there'll be a race as
|
/* uClinux will vfork(), so there'll be a race as
|
||||||
connection_string is freed below. */
|
connection_string is freed below. */
|
||||||
#ifndef USE_VFORK
|
#ifndef USE_VFORK
|
||||||
chansess->connection_string = make_connection_string();
|
make_connection_string(chansess);
|
||||||
chansess->client_string = make_client_string();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (chansess->term == NULL) {
|
if (chansess->term == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user