channel = ssh_channel_new(session);
if (channel == NULL) {
LX_ERROR("cannot create a new SSH channel: %s\n",
- ssh_get_error(session));
+ ssh_get_error(session));
rc = SSH_ERROR;
goto out;
}
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK) {
- LX_ERROR("cannot open SSH session channel: %s\n",
- ssh_get_error(session));
+ LX_ERROR("cannot open SSH session channel: %d: %s\n",
+ rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}
rc = ssh_channel_request_exec(channel, cmd);
if (rc != SSH_OK) {
- LX_ERROR("cannot execute SSH command: %s\n",
- ssh_get_error(session));
+ LX_ERROR("cannot execute SSH command: %d: %s\n",
+ rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}
return rc;
rc = ssh_channel_get_exit_status(channel);
- if (rc < 0)
+ if (rc < 0) {
+ LX_ERROR("lipe_ssh_session_start_cmd failed: %d: %s\n",
+ rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
+ }
*pstatus = rc;
- rc = 0;
+ rc = SSH_OK;
out:
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
session = ssh_new();
if (session == NULL) {
- LX_ERROR("cannot create a new SSH session: %s\n",
- strerror(ENOMEM)); /* Probably. */
+ LX_ERROR("cannot create a new SSH session: '%s'\n",
+ strerror(ENOMEM)); /* Probably. */
rc = SSH_ERROR;
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_HOST, host);
if (rc != SSH_OK) {
- LX_ERROR("cannot set SSH session host to '%s': %s\n",
- host, ssh_get_error(session));
+ LX_ERROR("cannot set SSH session host to '%s': %d: %s\n",
+ host, rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &timeout);
if (rc != SSH_OK) {
- LX_ERROR("cannot set SSH timeout to %ld: %s\n",
- timeout, ssh_get_error(session));
+ LX_ERROR("cannot set SSH timeout to %ld: %d: %s\n",
+ timeout, rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}
/* Connect to the ssh server */
rc = ssh_connect(session);
if (rc != SSH_OK) {
- LX_ERROR("cannot connect SSH session to host '%s': %s\n",
- host, ssh_get_error(session));
+ LX_ERROR("cannot connect SSH session to host '%s': %d: %s\n",
+ host, rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}
/* Automatically authenticate with public key */
rc = ssh_userauth_publickey_auto(session, NULL, NULL);
if (rc != SSH_AUTH_SUCCESS) {
- LX_ERROR("cannot authenticate SSH session to host '%s': %s\n",
- host, ssh_get_error(session));
+ LX_ERROR("cannot authenticate SSH session to host '%s': %d: %s\n",
+ host, rc, ssh_get_error(session));
+ rc = SSH_ERROR;
goto out;
}