Skip to content

Commit 2ba31f0

Browse files
committed
Add timeout control for SSH handshake and authentication
1 parent eab7a12 commit 2ba31f0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/net_server.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static ssh_channel new_session_channel(ssh_session session, void *userdata)
125125
static int fork_server(void)
126126
{
127127
ssh_event event;
128+
long int ssh_timeout = 0;
128129
int pid;
129130
int i;
130131
int ret;
@@ -176,6 +177,13 @@ static int fork_server(void)
176177
ssh_callbacks_init(&cb);
177178
ssh_set_server_callbacks(SSH_session, &cb);
178179

180+
ssh_timeout = 60; // second
181+
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
182+
{
183+
log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session));
184+
goto cleanup;
185+
}
186+
179187
if (ssh_handle_key_exchange(SSH_session))
180188
{
181189
log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session));
@@ -201,6 +209,13 @@ static int fork_server(void)
201209
log_error("SSH auth error, tried %d times\n", cb_data.tries);
202210
goto cleanup;
203211
}
212+
213+
ssh_timeout = 0;
214+
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
215+
{
216+
log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session));
217+
goto cleanup;
218+
}
204219
}
205220

206221
// Redirect Input

0 commit comments

Comments
 (0)