Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ AC_ARG_ENABLE([examples],
[AS_HELP_STRING([--disable-examples],[Disable examples (default: enabled)])],
[ENABLED_EXAMPLES=$enableval],[ENABLED_EXAMPLES=yes])

# Remove server code
AC_ARG_ENABLE([server],
[AS_HELP_STRING([--disable-server],[Disable server code (default: enabled)])],
[ENABLED_SERVER=$enableval],[ENABLED_SERVER=yes])

# Remove client code
AC_ARG_ENABLE([client],
[AS_HELP_STRING([--disable-client],[Disable client code (default: enabled)])],
[ENABLED_CLIENT=$enableval],[ENABLED_CLIENT=yes])

# Key Generation
AC_ARG_ENABLE([keygen],
[AS_HELP_STRING([--enable-keygen],[Enable key generation (default: disabled)])],
Expand Down Expand Up @@ -213,6 +223,10 @@ AS_IF([test "x$ENABLED_SSHD" = "xyes"],
# Set the defined flags for the code.
AS_IF([test "x$ENABLED_INLINE" = "xno"],
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_INLINE"])
AS_IF([test "x$ENABLED_SERVER" = "xno"],
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_WOLFSSH_SERVER"])
AS_IF([test "x$ENABLED_CLIENT" = "xno"],
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_WOLFSSH_CLIENT"])
AS_IF([test "x$ENABLED_KEYGEN" = "xyes"],
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_KEYGEN"])
AS_IF([test "x$ENABLED_KEYBOARD_INTERACTIVE" = "xyes"],
Expand Down
70 changes: 48 additions & 22 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ static int SendPacketType(WOLFSSH* ssh, byte type, byte* buf, word32 bufSz);
static int SFTP_ParseAtributes_buffer(WOLFSSH* ssh, WS_SFTP_FILEATRB* atr,
byte* buf, word32* idx, word32 maxIdx);
static WS_SFTPNAME* wolfSSH_SFTPNAME_new(void* heap);
#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_DIR)
static int SFTP_CreateLongName(WS_SFTPNAME* name);
#endif


/* A few errors are OK to get. They are a notice rather that a fault.
Expand Down Expand Up @@ -902,6 +904,7 @@ static int SFTP_SetHeader(WOLFSSH* ssh, word32 reqId, byte type, word32 len,
return WS_SUCCESS;
}

#ifndef NO_WOLFSSH_SERVER
static int SFTP_CreatePacket(WOLFSSH* ssh, byte type, byte* out, word32 outSz,
byte* data, word32 dataSz)
{
Expand All @@ -925,6 +928,7 @@ static int SFTP_CreatePacket(WOLFSSH* ssh, byte type, byte* out, word32 outSz,
}
return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_SERVER */


/* returns the size of buffer needed to hold attributes */
Expand Down Expand Up @@ -1038,11 +1042,13 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,
}


#ifndef NO_WOLFSSH_SERVER

#if !defined(WOLFSSH_USER_FILESYSTEM)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap);
#endif

#ifndef NO_WOLFSSH_SERVER
#if !defined(WOLFSSH_USER_FILESYSTEM)
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr);
#endif
Expand Down Expand Up @@ -3380,7 +3386,9 @@ static int wolfSSH_SFTP_SendName(WOLFSSH* ssh, WS_SFTPNAME* list, word32 count,

return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_DIR */

#endif /* !NO_WOLFSSH_SERVER */

int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
{
Expand All @@ -3401,6 +3409,9 @@ int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
return WS_SUCCESS;
}

#ifndef NO_WOLFSSH_SERVER

#ifndef NO_WOLFSSH_DIR

/* Handles packet to read a directory
*
Expand Down Expand Up @@ -3591,6 +3602,7 @@ int wolfSSH_SFTP_RecvCloseDir(WOLFSSH* ssh, byte* handle, word32 handleSz)

return WS_SUCCESS;
}

#endif /* NO_WOLFSSH_DIR */

/* Handles packet to write a file
Expand Down Expand Up @@ -4481,6 +4493,7 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
}
#endif /* WOLFSSH_STOREHANDLE */

#endif /* !NO_WOLFSSH_SERVER */

#if defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support */
Expand Down Expand Up @@ -4530,8 +4543,8 @@ static word32 TimeTo32(word16 d, word16 t)
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
DSTAT stats;
int sz = (int)WSTRLEN(fileName);
Expand Down Expand Up @@ -4601,13 +4614,14 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
}


#ifndef NO_WOLFSSH_SERVER
/* @TODO can be overridden by user for portability
* Gets attributes based on file descriptor
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
DSTAT stats;
Expand Down Expand Up @@ -4655,6 +4669,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
NU_Done(&stats);
return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_SERVER */

#elif defined(USE_WINDOWS_API)

Expand All @@ -4663,8 +4678,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
BOOL error;
WIN32_FILE_ATTRIBUTE_DATA stats;
Expand Down Expand Up @@ -4709,8 +4724,8 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success */
int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
int err, sz;
MQX_FILE_PTR mfs_ptr;
Expand Down Expand Up @@ -4764,13 +4779,14 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
return WS_SUCCESS;
}

#ifndef NO_WOLFSSH_SERVER
/* @TODO can be overridden by user for portability
* Gets attributes based on file descriptor
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success */
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
int err;
MQX_FILE_PTR mfs_ptr;
Expand Down Expand Up @@ -4815,6 +4831,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,

return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_SERVER */

#elif defined(WOLFSSH_FATFS)

Expand Down Expand Up @@ -4883,6 +4900,7 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
return WS_SUCCESS;
}

#ifndef NO_WOLFSSH_SERVER
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
Expand Down Expand Up @@ -4930,6 +4948,7 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WOLFSSH_UNUSED(handleSz);
return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_SERVER */

#elif defined(WOLFSSH_ZEPHYR)

Expand All @@ -4954,8 +4973,8 @@ static int PopulateAttributes(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
return WS_SUCCESS;
}

int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
WSTAT_T stats;

Expand All @@ -4969,7 +4988,8 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
return PopulateAttributes(atr, &stats);
}

int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
#ifndef NO_WOLFSSH_SERVER
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
WOLFSSH_UNUSED(ssh);
Expand All @@ -4981,6 +5001,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
return WS_NOT_COMPILED;
}
#endif /* !NO_WOLFSSH_SERVER */

#elif defined(MICROCHIP_MPLAB_HARMONY)
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
Expand Down Expand Up @@ -5052,8 +5073,8 @@ static int SFTP_GetAttributesHelper(WS_SFTP_FILEATRB* atr, const char* fName)
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
WOLFSSH_UNUSED(heap);
WOLFSSH_UNUSED(fs);
Expand All @@ -5068,20 +5089,22 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
#ifndef NO_WOLFSSH_SERVER
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
return SFTP_GetAttributesHelper(atr, name);
}
#endif /* !NO_WOLFSSH_SERVER */

#else

/* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
byte noFollow, void* heap)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap)
{
WSTAT_T stats;

Expand Down Expand Up @@ -5125,13 +5148,14 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
}


#ifndef NO_WOLFSSH_SERVER
/* @TODO can be overridden by user for portability
* Gets attributes based on file descriptor
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
struct stat stats;
Expand Down Expand Up @@ -5169,8 +5193,10 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WOLFSSH_UNUSED(name);
return WS_SUCCESS;
}
#endif /* !NO_WOLFSSH_SERVER */
#endif

#ifndef NO_WOLFSSH_SERVER

#ifndef USE_WINDOWS_API
/* Handles receiving fstat packet
Expand Down Expand Up @@ -9273,7 +9299,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
ret = SFTP_FreeHandles(ssh);
#endif

#ifndef NO_WOLFSSH_DIR
#if !defined(NO_WOLFSSH_DIR) && !defined(NO_WOLFSSH_SERVER)
{
/* free all dirs if hung up on */
WS_DIR_LIST* cur = ssh->dirList;
Expand All @@ -9294,7 +9320,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
}
ssh->dirList = NULL;
}
#endif /* NO_WOLFSSH_DIR */
#endif /* !NO_WOLFSSH_DIR && !NO_WOLFSSH_SERVER */

wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
return ret;
Expand Down
4 changes: 4 additions & 0 deletions wolfssh/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ extern "C" {
* at least one algorithm to use, throw an error.
*/

#if defined(NO_WOLFSSH_SERVER) && defined(NO_WOLFSSH_CLIENT)
#error "Both NO_WOLFSSH_SERVER and NO_WOLFSSH_CLIENT are defined. Omit one of --disable-server or --disable-client."
#endif

#ifdef NO_RSA
#undef WOLFSSH_NO_RSA
#define WOLFSSH_NO_RSA
Expand Down
2 changes: 1 addition & 1 deletion wolfssh/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ extern "C" {

#if (defined(WOLFSSH_SFTP) || \
defined(WOLFSSH_SCP) || defined(WOLFSSH_SSHD)) && \
!defined(NO_WOLFSSH_SERVER) && \
!(defined(NO_WOLFSSH_SERVER) && defined(NO_WOLFSSH_CLIENT)) && \
(!defined(NO_FILESYSTEM) || defined(WOLFSSH_FATFS))

#ifndef SIZEOF_OFF_T
Expand Down