| 333 |
|
|
| 334 |
ssh_bind_free(sshbind); |
ssh_bind_free(sshbind); |
| 335 |
|
|
|
ssh_callbacks_init(&channel_cb); |
|
|
ssh_callbacks_init(&server_cb); |
|
|
|
|
|
ssh_set_server_callbacks(SSH_session, &server_cb); |
|
|
|
|
| 336 |
ssh_timeout = 60; // second |
ssh_timeout = 60; // second |
| 337 |
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
| 338 |
{ |
{ |
| 340 |
goto cleanup; |
goto cleanup; |
| 341 |
} |
} |
| 342 |
|
|
| 343 |
|
ssh_set_auth_methods(SSH_session, SSH_AUTH_METHOD_PASSWORD); |
| 344 |
|
|
| 345 |
|
ssh_callbacks_init(&server_cb); |
| 346 |
|
ssh_callbacks_init(&channel_cb); |
| 347 |
|
|
| 348 |
|
ssh_set_server_callbacks(SSH_session, &server_cb); |
| 349 |
|
|
| 350 |
if (ssh_handle_key_exchange(SSH_session)) |
if (ssh_handle_key_exchange(SSH_session)) |
| 351 |
{ |
{ |
| 352 |
log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session)); |
| 353 |
goto cleanup; |
goto cleanup; |
| 354 |
} |
} |
|
ssh_set_auth_methods(SSH_session, SSH_AUTH_METHOD_PASSWORD); |
|
| 355 |
|
|
| 356 |
event = ssh_event_new(); |
event = ssh_event_new(); |
| 357 |
ssh_event_add_session(event, SSH_session); |
ssh_event_add_session(event, SSH_session); |
| 376 |
|
|
| 377 |
ssh_set_channel_callbacks(SSH_channel, &channel_cb); |
ssh_set_channel_callbacks(SSH_channel, &channel_cb); |
| 378 |
|
|
| 379 |
|
do |
| 380 |
|
{ |
| 381 |
|
ret = ssh_event_dopoll(event, 100); // 0.1 second |
| 382 |
|
if (ret == SSH_ERROR) |
| 383 |
|
{ |
| 384 |
|
ssh_channel_close(SSH_channel); |
| 385 |
|
} |
| 386 |
|
|
| 387 |
|
if (ret == SSH_AGAIN) // loop until SSH connection is fully established |
| 388 |
|
{ |
| 389 |
|
/* Executed only once, once the child process starts. */ |
| 390 |
|
cdata.event = event; |
| 391 |
|
break; |
| 392 |
|
} |
| 393 |
|
} while (ssh_channel_is_open(SSH_channel)); |
| 394 |
|
|
| 395 |
ssh_timeout = 0; |
ssh_timeout = 0; |
| 396 |
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
| 397 |
{ |
{ |