1
1

include: Fix segfault in getIssueBanner, add missing wrappers in libsshpp

Also make some private properties protected

Signed-off-by: Marcin Szalowicz <marcin.szalowicz@oracle.com>
Этот коммит содержится в:
Marcin Szalowicz 2018-06-11 11:25:43 +02:00 коммит произвёл Andreas Schneider
родитель a86d1d335b
Коммит 5ea81166bf

Просмотреть файл

@ -194,6 +194,43 @@ public:
ssh_throw(ret);
return ret;
}
/** @brief Authenticate through the "keyboard-interactive" method.
* @param[in] The username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
* @param[in] Undocumented. Set it to NULL.
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED, SSH_AUTH_ERROR, SSH_AUTH_INFO, SSH_AUTH_AGAIN
* @see ssh_userauth_kbdint
*/
int userauthKbdint(const char* username, const char* submethods){
int ret=ssh_userauth_kbdint(c_session,NULL,NULL);
ssh_throw(ret);
return ret;
}
/** @brief Get the number of prompts (questions) the server has given.
* @returns The number of prompts.
* @see ssh_userauth_kbdint_getnprompts
*/
int userauthKbdintGetNPrompts(){
return ssh_userauth_kbdint_getnprompts(c_session);
}
/** @brief Set the answer for a question from a message block..
* @param[in] index The number of the ith prompt.
* @param[in] The answer to give to the server. The answer MUST be encoded UTF-8. It is up to the server how to interpret the value and validate it. However, if you read the answer in some other encoding, you MUST convert it to UTF-8.
* @throws SshException on error
* @returns 0 on success, < 0 on error
* @see ssh_userauth_kbdint_setanswer
*/
int userauthKbdintSetAnswer(unsigned int i, const char* answer){
int ret=ssh_userauth_kbdint_setanswer(c_session, i, answer);
ssh_throw(ret);
return ret;
}
/** @brief Authenticates using the password method.
* @param[in] password password to use for authentication
* @throws SshException on error
@ -228,8 +265,7 @@ public:
ssh_throw(ret);
return ret;
}
int userauthPrivatekeyFile(const char *filename,
const char *passphrase);
/** @brief Returns the available authentication methods from the server
* @throws SshException on error
* @returns Bitfield of available methods.
@ -281,8 +317,12 @@ public:
*/
std::string getIssueBanner(){
char *banner=ssh_get_issue_banner(c_session);
std::string ret= std::string(banner);
::free(banner);
std::string ret;
if (banner)
{
ret= std::string(banner);
::free(banner);
}
return ret;
}
/** @brief returns the OpenSSH version (server) if possible
@ -378,11 +418,14 @@ public:
return_throwable;
}
private:
ssh_session c_session;
ssh_session getCSession(){
return c_session;
}
protected:
ssh_session c_session;
private:
/* No copy constructor, no = operator */
Session(const Session &);
Session& operator=(const Session &);
@ -481,12 +524,12 @@ public:
ssh_throw(err);
return err;
}
int read(void *dest, size_t count, bool is_stderr){
int read(void *dest, size_t count){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
err=ssh_channel_read_timeout(channel,dest,count,is_stderr,-1);
err=ssh_channel_read_timeout(channel,dest,count,false,-1);
ssh_throw(err);
return err;
}
@ -584,16 +627,24 @@ public:
ssh_throw(ret);
return ret;
}
private:
ssh_session getCSession(){
return session->getCSession();
}
ssh_channel getCChannel() {
return channel;
}
protected:
Session *session;
ssh_channel channel;
private:
Channel (Session &session, ssh_channel c_channel){
this->channel=c_channel;
this->session=&session;
}
Session *session;
ssh_channel channel;
/* No copy and no = operator */
Channel(const Channel &);
Channel &operator=(const Channel &);