Skip to content
Open
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
32 changes: 27 additions & 5 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);
#ifndef NO_WOLFSSH_SERVER
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 @@ -3402,7 +3408,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 @@ -3423,6 +3431,7 @@ int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
return WS_SUCCESS;
}

#ifndef NO_WOLFSSH_SERVER

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

return WS_SUCCESS;
}
#endif /* NO_WOLFSSH_DIR */

/* Handles packet to write a file
Comment on lines 3622 to 3626
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directory packet handlers are now only guarded by #ifndef NO_WOLFSSH_SERVER, but the corresponding NO_WOLFSSH_DIR guard closure was removed (#endif /* NO_WOLFSSH_DIR */). This makes the directory-specific code compile even when NO_WOLFSSH_DIR is defined, which can break NO_WOLFSSH_DIR builds (missing types/fields or unwanted directory functionality). Wrap the directory-specific handler section (e.g., the 'read a directory' / close-dir handlers) in #if !defined(NO_WOLFSSH_DIR) (or a combined !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_DIR)), and ensure the #if/#endif pairing matches the new structure so non-directory server handlers remain available when NO_WOLFSSH_DIR is set.

Copilot uses AI. Check for mistakes.
*
Expand Down Expand Up @@ -4503,6 +4511,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 @@ -4623,6 +4632,7 @@ 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.
Expand Down Expand Up @@ -4677,6 +4687,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 Down Expand Up @@ -4786,6 +4797,7 @@ 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.
Expand Down Expand Up @@ -4837,6 +4849,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 @@ -4905,6 +4918,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 @@ -4952,6 +4966,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 Down Expand Up @@ -4991,6 +5006,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
return PopulateAttributes(atr, &stats);
}

#ifndef NO_WOLFSSH_SERVER
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
char* name, WS_SFTP_FILEATRB* atr)
{
Expand All @@ -5003,6 +5019,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 @@ -5090,11 +5107,13 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success
*/
#ifndef NO_WOLFSSH_SERVER
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

Expand Down Expand Up @@ -5147,6 +5166,7 @@ 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.
Expand Down Expand Up @@ -5191,8 +5211,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 @@ -9316,7 +9338,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 @@ -9337,7 +9359,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 "You cannot disable both server and 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