mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
sftp_aio.c, sftp.h: Add capping to sftp aio write 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
91990f9dfa
commit
188a9cf68f
@@ -738,6 +738,12 @@ LIBSSH_API ssize_t sftp_aio_wait_read(sftp_aio *aio,
|
|||||||
* calling sftp_close() or to keep it open and perform some more operations
|
* calling sftp_close() or to keep it open and perform some more operations
|
||||||
* on it.
|
* on it.
|
||||||
*
|
*
|
||||||
|
* This function caps the length a user is allowed to write to 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_write_length
|
||||||
|
* field of the sftp_limits_t returned by sftp_limits().
|
||||||
|
*
|
||||||
* @param file The opened sftp file handle to write to.
|
* @param file The opened sftp file handle to write to.
|
||||||
*
|
*
|
||||||
* @param buf Pointer to the buffer containing data to write.
|
* @param buf Pointer to the buffer containing data to write.
|
||||||
@@ -747,11 +753,14 @@ LIBSSH_API ssize_t sftp_aio_wait_read(sftp_aio *aio,
|
|||||||
* @param aio Pointer to a location where the sftp aio handle
|
* @param aio Pointer to a location where the sftp aio handle
|
||||||
* (corresponding to the sent request) should be stored.
|
* (corresponding to the sent request) should be stored.
|
||||||
*
|
*
|
||||||
* @returns SSH_OK on success, SSH_ERROR with sftp and ssh errors
|
* @returns On success, the number of bytes the server is
|
||||||
|
* requested to write (value of len parameter after
|
||||||
|
* capping). On error, SSH_ERROR with sftp and ssh errors
|
||||||
* set.
|
* set.
|
||||||
*
|
*
|
||||||
* @warning When calling this function, the internal offset is
|
* @warning When calling this function, the internal file offset is
|
||||||
* updated corresponding to the len parameter.
|
* updated corresponding to the number of bytes requested
|
||||||
|
* to write.
|
||||||
*
|
*
|
||||||
* @warning A call to sftp_aio_begin_write() sends a request to
|
* @warning A call to sftp_aio_begin_write() sends a request to
|
||||||
* the server. When the server answers, libssh allocates
|
* the server. When the server answers, libssh allocates
|
||||||
@@ -766,10 +775,10 @@ LIBSSH_API ssize_t sftp_aio_wait_read(sftp_aio *aio,
|
|||||||
* @see sftp_get_error()
|
* @see sftp_get_error()
|
||||||
* @see ssh_get_error()
|
* @see ssh_get_error()
|
||||||
*/
|
*/
|
||||||
LIBSSH_API int sftp_aio_begin_write(sftp_file file,
|
LIBSSH_API ssize_t sftp_aio_begin_write(sftp_file file,
|
||||||
const void *buf,
|
const void *buf,
|
||||||
size_t len,
|
size_t len,
|
||||||
sftp_aio *aio);
|
sftp_aio *aio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wait for an asynchronous write to complete.
|
* @brief Wait for an asynchronous write to complete.
|
||||||
@@ -784,11 +793,6 @@ LIBSSH_API int sftp_aio_begin_write(sftp_file file,
|
|||||||
* been executed yet, this function returns SSH_AGAIN and must be called
|
* been executed yet, this function returns SSH_AGAIN and must be called
|
||||||
* again using the same sftp aio handle.
|
* again using the same sftp aio handle.
|
||||||
*
|
*
|
||||||
* On success, this function returns the number of bytes written.
|
|
||||||
* The SFTP protocol doesn't support partial writes to remote files,
|
|
||||||
* hence on success this returned value will always be equal to the
|
|
||||||
* len passed in the previous corresponding call to sftp_aio_begin_write().
|
|
||||||
*
|
|
||||||
* @param aio Pointer to the sftp aio handle returned by
|
* @param aio Pointer to the sftp aio handle returned by
|
||||||
* sftp_aio_begin_write().
|
* sftp_aio_begin_write().
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -307,10 +307,10 @@ ssize_t sftp_aio_wait_read(sftp_aio *aio,
|
|||||||
return SSH_ERROR; /* not reached */
|
return SSH_ERROR; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
int sftp_aio_begin_write(sftp_file file,
|
ssize_t sftp_aio_begin_write(sftp_file file,
|
||||||
const void *buf,
|
const void *buf,
|
||||||
size_t len,
|
size_t len,
|
||||||
sftp_aio *aio)
|
sftp_aio *aio)
|
||||||
{
|
{
|
||||||
sftp_session sftp = NULL;
|
sftp_session sftp = NULL;
|
||||||
ssh_buffer buffer = NULL;
|
ssh_buffer buffer = NULL;
|
||||||
@@ -341,6 +341,11 @@ int sftp_aio_begin_write(sftp_file file,
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Apply a cap on the length a user is allowed to write */
|
||||||
|
if (len > sftp->limits->max_write_length) {
|
||||||
|
len = sftp->limits->max_write_length;
|
||||||
|
}
|
||||||
|
|
||||||
if (aio == NULL) {
|
if (aio == NULL) {
|
||||||
ssh_set_error(sftp->session, SSH_FATAL,
|
ssh_set_error(sftp->session, SSH_FATAL,
|
||||||
"Invalid argument, NULL passed instead of a pointer to "
|
"Invalid argument, NULL passed instead of a pointer to "
|
||||||
@@ -394,7 +399,7 @@ int sftp_aio_begin_write(sftp_file file,
|
|||||||
/* Assume we wrote len bytes to the file */
|
/* Assume we wrote len bytes to the file */
|
||||||
file->offset += len;
|
file->offset += len;
|
||||||
*aio = aio_handle;
|
*aio = aio_handle;
|
||||||
return SSH_OK;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t sftp_aio_wait_write(sftp_aio *aio)
|
ssize_t sftp_aio_wait_write(sftp_aio *aio)
|
||||||
|
|||||||
Reference in New Issue
Block a user