Skip to content

Commit 392896d

Browse files
committed
No Server Guard Update
1. Adds --disable-server and --disable-client configure flags. Allows for compile-time exclusion of server or client code. 2. Add check to internal.h for both NO_WOLFSSH_SERVER and NO_WOLFSSH_CLIENT being set and errors. 3. In ports.h, add check for not-NO_WOLFSSH_CLIENT so SFTP/SCP filesystrem types are also available in client-only builds. 4. Update the NO_WOLFSSH_SERVER and NO_WOLFSSH_DIR guards around wolfsftp.c. Update wolfSSH_SFTP_free() to skip directory cleanup when server code is disabled. ZD #21261
1 parent 1e1140a commit 392896d

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

configure.ac

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ AC_ARG_ENABLE([examples],
121121
[AS_HELP_STRING([--disable-examples],[Disable examples (default: enabled)])],
122122
[ENABLED_EXAMPLES=$enableval],[ENABLED_EXAMPLES=yes])
123123

124+
# Remove server code
125+
AC_ARG_ENABLE([server],
126+
[AS_HELP_STRING([--disable-server],[Disable server code (default: enabled)])],
127+
[ENABLED_SERVER=$enableval],[ENABLED_SERVER=yes])
128+
129+
# Remove client code
130+
AC_ARG_ENABLE([client],
131+
[AS_HELP_STRING([--disable-client],[Disable client code (default: enabled)])],
132+
[ENABLED_CLIENT=$enableval],[ENABLED_CLIENT=yes])
133+
124134
# Key Generation
125135
AC_ARG_ENABLE([keygen],
126136
[AS_HELP_STRING([--enable-keygen],[Enable key generation (default: disabled)])],
@@ -213,6 +223,10 @@ AS_IF([test "x$ENABLED_SSHD" = "xyes"],
213223
# Set the defined flags for the code.
214224
AS_IF([test "x$ENABLED_INLINE" = "xno"],
215225
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_INLINE"])
226+
AS_IF([test "x$ENABLED_SERVER" = "xno"],
227+
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_WOLFSSH_SERVER"])
228+
AS_IF([test "x$ENABLED_CLIENT" = "xno"],
229+
[AM_CPPFLAGS="$AM_CPPFLAGS -DNO_WOLFSSH_CLIENT"])
216230
AS_IF([test "x$ENABLED_KEYGEN" = "xyes"],
217231
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_KEYGEN"])
218232
AS_IF([test "x$ENABLED_KEYBOARD_INTERACTIVE" = "xyes"],

src/wolfsftp.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ static int SendPacketType(WOLFSSH* ssh, byte type, byte* buf, word32 bufSz);
406406
static int SFTP_ParseAtributes_buffer(WOLFSSH* ssh, WS_SFTP_FILEATRB* atr,
407407
byte* buf, word32* idx, word32 maxIdx);
408408
static WS_SFTPNAME* wolfSSH_SFTPNAME_new(void* heap);
409+
#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_DIR)
409410
static int SFTP_CreateLongName(WS_SFTPNAME* name);
411+
#endif
410412

411413

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

907+
#ifndef NO_WOLFSSH_SERVER
905908
static int SFTP_CreatePacket(WOLFSSH* ssh, byte type, byte* out, word32 outSz,
906909
byte* data, word32 dataSz)
907910
{
@@ -925,6 +928,7 @@ static int SFTP_CreatePacket(WOLFSSH* ssh, byte type, byte* out, word32 outSz,
925928
}
926929
return WS_SUCCESS;
927930
}
931+
#endif /* !NO_WOLFSSH_SERVER */
928932

929933

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

10401044

1041-
#ifndef NO_WOLFSSH_SERVER
1042-
10431045
#if !defined(WOLFSSH_USER_FILESYSTEM)
10441046
static int SFTP_GetAttributes(void* fs, const char* fileName,
10451047
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap);
1048+
#endif
1049+
1050+
#ifndef NO_WOLFSSH_SERVER
1051+
#if !defined(WOLFSSH_USER_FILESYSTEM)
10461052
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
10471053
char* name, WS_SFTP_FILEATRB* atr);
10481054
#endif
@@ -3380,7 +3386,9 @@ static int wolfSSH_SFTP_SendName(WOLFSSH* ssh, WS_SFTPNAME* list, word32 count,
33803386

33813387
return WS_SUCCESS;
33823388
}
3389+
#endif /* !NO_WOLFSSH_DIR */
33833390

3391+
#endif /* !NO_WOLFSSH_SERVER */
33843392

33853393
int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
33863394
{
@@ -3401,6 +3409,9 @@ int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
34013409
return WS_SUCCESS;
34023410
}
34033411

3412+
#ifndef NO_WOLFSSH_SERVER
3413+
3414+
#ifndef NO_WOLFSSH_DIR
34043415

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

35923603
return WS_SUCCESS;
35933604
}
3605+
35943606
#endif /* NO_WOLFSSH_DIR */
35953607

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

4496+
#endif /* !NO_WOLFSSH_SERVER */
44844497

44854498
#if defined(WOLFSSH_USER_FILESYSTEM)
44864499
/* User-defined I/O support */
@@ -4601,6 +4614,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
46014614
}
46024615

46034616

4617+
#ifndef NO_WOLFSSH_SERVER
46044618
/* @TODO can be overridden by user for portability
46054619
* Gets attributes based on file descriptor
46064620
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -4655,6 +4669,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
46554669
NU_Done(&stats);
46564670
return WS_SUCCESS;
46574671
}
4672+
#endif /* !NO_WOLFSSH_SERVER */
46584673

46594674
#elif defined(USE_WINDOWS_API)
46604675

@@ -4764,6 +4779,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47644779
return WS_SUCCESS;
47654780
}
47664781

4782+
#ifndef NO_WOLFSSH_SERVER
47674783
/* @TODO can be overridden by user for portability
47684784
* Gets attributes based on file descriptor
47694785
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -4815,6 +4831,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
48154831

48164832
return WS_SUCCESS;
48174833
}
4834+
#endif /* !NO_WOLFSSH_SERVER */
48184835

48194836
#elif defined(WOLFSSH_FATFS)
48204837

@@ -4883,6 +4900,7 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
48834900
return WS_SUCCESS;
48844901
}
48854902

4903+
#ifndef NO_WOLFSSH_SERVER
48864904
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
48874905
char* name, WS_SFTP_FILEATRB* atr)
48884906
{
@@ -4930,6 +4948,7 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49304948
WOLFSSH_UNUSED(handleSz);
49314949
return WS_SUCCESS;
49324950
}
4951+
#endif /* !NO_WOLFSSH_SERVER */
49334952

49344953
#elif defined(WOLFSSH_ZEPHYR)
49354954

@@ -4969,6 +4988,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49694988
return PopulateAttributes(atr, &stats);
49704989
}
49714990

4991+
#ifndef NO_WOLFSSH_SERVER
49724992
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49734993
char* name, WS_SFTP_FILEATRB* atr)
49744994
{
@@ -4981,6 +5001,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49815001
WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
49825002
return WS_NOT_COMPILED;
49835003
}
5004+
#endif /* !NO_WOLFSSH_SERVER */
49845005

49855006
#elif defined(MICROCHIP_MPLAB_HARMONY)
49865007
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
@@ -5068,11 +5089,13 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50685089
* Fills out a WS_SFTP_FILEATRB structure
50695090
* returns WS_SUCCESS on success
50705091
*/
5092+
#ifndef NO_WOLFSSH_SERVER
50715093
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
50725094
char* name, WS_SFTP_FILEATRB* atr)
50735095
{
50745096
return SFTP_GetAttributesHelper(atr, name);
50755097
}
5098+
#endif /* !NO_WOLFSSH_SERVER */
50765099

50775100
#else
50785101

@@ -5125,6 +5148,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
51255148
}
51265149

51275150

5151+
#ifndef NO_WOLFSSH_SERVER
51285152
/* @TODO can be overridden by user for portability
51295153
* Gets attributes based on file descriptor
51305154
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -5169,8 +5193,10 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
51695193
WOLFSSH_UNUSED(name);
51705194
return WS_SUCCESS;
51715195
}
5196+
#endif /* !NO_WOLFSSH_SERVER */
51725197
#endif
51735198

5199+
#ifndef NO_WOLFSSH_SERVER
51745200

51755201
#ifndef USE_WINDOWS_API
51765202
/* Handles receiving fstat packet
@@ -9273,7 +9299,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
92739299
ret = SFTP_FreeHandles(ssh);
92749300
#endif
92759301

9276-
#ifndef NO_WOLFSSH_DIR
9302+
#if !defined(NO_WOLFSSH_DIR) && !defined(NO_WOLFSSH_SERVER)
92779303
{
92789304
/* free all dirs if hung up on */
92799305
WS_DIR_LIST* cur = ssh->dirList;
@@ -9294,7 +9320,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
92949320
}
92959321
ssh->dirList = NULL;
92969322
}
9297-
#endif /* NO_WOLFSSH_DIR */
9323+
#endif /* !NO_WOLFSSH_DIR && !NO_WOLFSSH_SERVER */
92989324

92999325
wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
93009326
return ret;

wolfssh/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ extern "C" {
8888
* at least one algorithm to use, throw an error.
8989
*/
9090

91+
#if defined(NO_WOLFSSH_SERVER) && defined(NO_WOLFSSH_CLIENT)
92+
#error "You cannot disable both server and client."
93+
#endif
94+
9195
#ifdef NO_RSA
9296
#undef WOLFSSH_NO_RSA
9397
#define WOLFSSH_NO_RSA

wolfssh/port.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ extern "C" {
640640

641641
#if (defined(WOLFSSH_SFTP) || \
642642
defined(WOLFSSH_SCP) || defined(WOLFSSH_SSHD)) && \
643-
!defined(NO_WOLFSSH_SERVER) && \
643+
(!defined(NO_WOLFSSH_SERVER) || !defined(NO_WOLFSSH_CLIENT)) && \
644644
(!defined(NO_FILESYSTEM) || defined(WOLFSSH_FATFS))
645645

646646
#ifndef SIZEOF_OFF_T

0 commit comments

Comments
 (0)