1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-04-17 11:46:39 +02:00

Cleanup of init/handshake in storageSftpNew().

Rename handshakeStatus to rc to be consistent with the rest of the module.

Add comments and do some reformatting.
This commit is contained in:
David Steele 2023-07-07 09:56:26 +02:00
parent 9efd5cd0bb
commit 125676ae0e

View File

@ -761,31 +761,33 @@ storageSftpNew(
.timeout = timeout, .timeout = timeout,
}; };
// Init SFTP session
if (libssh2_init(0) != 0) if (libssh2_init(0) != 0)
THROW_FMT(ServiceError, "unable to init libssh2"); THROW_FMT(ServiceError, "unable to init libssh2");
this->ioSession = ioClientOpen(sckClientNew(host, port, timeout, timeout)); this->ioSession = ioClientOpen(sckClientNew(host, port, timeout, timeout));
this->session = libssh2_session_init(); this->session = libssh2_session_init();
if (this->session == NULL) if (this->session == NULL)
THROW_FMT(ServiceError, "unable to init libssh2 session"); THROW_FMT(ServiceError, "unable to init libssh2 session");
// Returns void // Set session to non-blocking
libssh2_session_set_blocking(this->session, 0); libssh2_session_set_blocking(this->session, 0);
int handshakeStatus = 0; // Perform handshake
int rc;
Wait *wait = waitNew(timeout); Wait *wait = waitNew(timeout);
do do
{ {
handshakeStatus = libssh2_session_handshake(this->session, ioSessionFd(this->ioSession)); rc = libssh2_session_handshake(this->session, ioSessionFd(this->ioSession));
} }
while (handshakeStatus == LIBSSH2_ERROR_EAGAIN && waitMore(wait)); while (rc == LIBSSH2_ERROR_EAGAIN && waitMore(wait));
waitFree(wait); waitFree(wait);
if (handshakeStatus != 0) if (rc != 0)
THROW_FMT(ServiceError, "libssh2 handshake failed [%d]", handshakeStatus); THROW_FMT(ServiceError, "libssh2 handshake failed [%d]", rc);
int hashType = LIBSSH2_HOSTKEY_HASH_SHA1; int hashType = LIBSSH2_HOSTKEY_HASH_SHA1;
size_t hashSize = 0; size_t hashSize = 0;
@ -838,9 +840,6 @@ storageSftpNew(
} }
} }
LOG_DEBUG_FMT("attempting public key authentication");
int rc;
wait = waitNew(timeout); wait = waitNew(timeout);
do do