Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wolfSSH_SFTPNAME_readdir overridable #552

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2616,8 +2616,42 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name)
return WS_SUCCESS;
}

#if defined (WOLFSSH_SFTP_NAME_READDIR)
/* helper function that gets file information from reading directory.
* Internally uses SFTP_Name_readdir to delegate the work to the User Filesystem.
*
* returns WS_SUCCESS on success
*/
static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
char* dirName)
{
WOLFSSH_UNUSED(dirName);
int res;

#ifdef WOLFSSL_NUCLEUS
if (dir == NULL || ssh == NULL || out == NULL) {
return WS_BAD_ARGUMENT;
}

res = SFTP_Name_readdir(ssh->fs, dir, out);
if (res != WS_SUCCESS) {
return res;
}

if (out->fName == NULL) {
return WS_MEMORY_E;
}

/* Use attributes and fName to create long name */
if (SFTP_CreateLongName(out) != WS_SUCCESS) {
WLOG(WS_LOG_DEBUG, "Error creating long name for %s", out->fName);
WFREE(out->fName, out->heap, DYNTYPE_SFTP);
return WS_FATAL_ERROR;
}

return WS_SUCCESS;
}

#elif defined(WOLFSSL_NUCLEUS)
/* For Nucleus port
* helper function that gets file information from reading directory
* @TODO allow user to override
Expand Down Expand Up @@ -2997,7 +3031,6 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
{
char r[WOLFSSH_MAX_FILENAME];
char s[WOLFSSH_MAX_FILENAME];

if ((WSTRLEN(dirName) + WSTRLEN(out->fName) + 2) > sizeof(r)) {
WLOG(WS_LOG_SFTP, "Path length too large");
WFREE(out->fName, out->heap, DYNTYPE_SFTP);
Expand Down