mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-08 03:42:12 +03:00
sftp_aio.c, sftp.h: Add capping to the sftp aio read API
Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
d2d5e717f3
commit
91990f9dfa
@@ -634,6 +634,12 @@ LIBSSH_API void sftp_aio_free(sftp_aio aio);
|
||||
* calling sftp_close() or to keep it open and perform some more operations
|
||||
* on it.
|
||||
*
|
||||
* This function caps the length a user is allowed to read from an sftp file,
|
||||
* the value of len parameter after capping is returned on success.
|
||||
*
|
||||
* The value used for the cap is same as the value of the max_read_length
|
||||
* field of the sftp_limits_t returned by sftp_limits().
|
||||
*
|
||||
* @param file The opened sftp file handle to be read from.
|
||||
*
|
||||
* @param len Number of bytes to read.
|
||||
@@ -641,11 +647,14 @@ LIBSSH_API void sftp_aio_free(sftp_aio aio);
|
||||
* @param aio Pointer to a location where the sftp aio handle
|
||||
* (corresponding to the sent request) should be stored.
|
||||
*
|
||||
* @returns SSH_OK on success, SSH_ERROR on error with sftp and ssh
|
||||
* @returns On success, the number of bytes the server is
|
||||
* requested to read (value of len parameter after
|
||||
* capping). On error, SSH_ERROR with sftp and ssh
|
||||
* errors set.
|
||||
*
|
||||
* @warning When calling this function, the internal offset is
|
||||
* updated corresponding to the len parameter.
|
||||
* @warning When calling this function, the internal file offset is
|
||||
* updated corresponding to the number of bytes requested
|
||||
* to read.
|
||||
*
|
||||
* @warning A call to sftp_aio_begin_read() sends a request to
|
||||
* the server. When the server answers, libssh allocates
|
||||
@@ -660,9 +669,9 @@ LIBSSH_API void sftp_aio_free(sftp_aio aio);
|
||||
* @see sftp_get_error()
|
||||
* @see ssh_get_error()
|
||||
*/
|
||||
LIBSSH_API int sftp_aio_begin_read(sftp_file file,
|
||||
size_t len,
|
||||
sftp_aio *aio);
|
||||
LIBSSH_API ssize_t sftp_aio_begin_read(sftp_file file,
|
||||
size_t len,
|
||||
sftp_aio *aio);
|
||||
|
||||
/**
|
||||
* @brief Wait for an asynchronous read to complete and store the read data
|
||||
|
||||
@@ -50,7 +50,7 @@ void sftp_aio_free(sftp_aio aio)
|
||||
SAFE_FREE(aio);
|
||||
}
|
||||
|
||||
int sftp_aio_begin_read(sftp_file file, size_t len, sftp_aio *aio)
|
||||
ssize_t sftp_aio_begin_read(sftp_file file, size_t len, sftp_aio *aio)
|
||||
{
|
||||
sftp_session sftp = NULL;
|
||||
ssh_buffer buffer = NULL;
|
||||
@@ -73,6 +73,11 @@ int sftp_aio_begin_read(sftp_file file, size_t len, sftp_aio *aio)
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
/* Apply a cap on the length a user is allowed to read */
|
||||
if (len > sftp->limits->max_read_length) {
|
||||
len = sftp->limits->max_read_length;
|
||||
}
|
||||
|
||||
if (aio == NULL) {
|
||||
ssh_set_error(sftp->session, SSH_FATAL,
|
||||
"Invalid argument, NULL passed instead of a pointer to "
|
||||
@@ -126,7 +131,7 @@ int sftp_aio_begin_read(sftp_file file, size_t len, sftp_aio *aio)
|
||||
/* Assume we read len bytes from the file */
|
||||
file->offset += len;
|
||||
*aio = aio_handle;
|
||||
return SSH_OK;
|
||||
return len;
|
||||
}
|
||||
|
||||
ssize_t sftp_aio_wait_read(sftp_aio *aio,
|
||||
|
||||
Reference in New Issue
Block a user