Skip to content

Commit b5f6948

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 9efdb7e commit b5f6948

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
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: 27 additions & 5 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+
#ifndef NO_WOLFSSH_SERVER
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
@@ -3402,7 +3408,9 @@ static int wolfSSH_SFTP_SendName(WOLFSSH* ssh, WS_SFTPNAME* list, word32 count,
34023408

34033409
return WS_SUCCESS;
34043410
}
3411+
#endif /* !NO_WOLFSSH_DIR */
34053412

3413+
#endif /* !NO_WOLFSSH_SERVER */
34063414

34073415
int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
34083416
{
@@ -3423,6 +3431,7 @@ int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path)
34233431
return WS_SUCCESS;
34243432
}
34253433

3434+
#ifndef NO_WOLFSSH_SERVER
34263435

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

36143623
return WS_SUCCESS;
36153624
}
3616-
#endif /* NO_WOLFSSH_DIR */
36173625

36183626
/* Handles packet to write a file
36193627
*
@@ -4503,6 +4511,7 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
45034511
}
45044512
#endif /* WOLFSSH_STOREHANDLE */
45054513

4514+
#endif /* !NO_WOLFSSH_SERVER */
45064515

45074516
#if defined(WOLFSSH_USER_FILESYSTEM)
45084517
/* User-defined I/O support */
@@ -4623,6 +4632,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
46234632
}
46244633

46254634

4635+
#ifndef NO_WOLFSSH_SERVER
46264636
/* @TODO can be overridden by user for portability
46274637
* Gets attributes based on file descriptor
46284638
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -4677,6 +4687,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
46774687
NU_Done(&stats);
46784688
return WS_SUCCESS;
46794689
}
4690+
#endif /* !NO_WOLFSSH_SERVER */
46804691

46814692
#elif defined(USE_WINDOWS_API)
46824693

@@ -4786,6 +4797,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47864797
return WS_SUCCESS;
47874798
}
47884799

4800+
#ifndef NO_WOLFSSH_SERVER
47894801
/* @TODO can be overridden by user for portability
47904802
* Gets attributes based on file descriptor
47914803
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -4837,6 +4849,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
48374849

48384850
return WS_SUCCESS;
48394851
}
4852+
#endif /* !NO_WOLFSSH_SERVER */
48404853

48414854
#elif defined(WOLFSSH_FATFS)
48424855

@@ -4905,6 +4918,7 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
49054918
return WS_SUCCESS;
49064919
}
49074920

4921+
#ifndef NO_WOLFSSH_SERVER
49084922
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49094923
char* name, WS_SFTP_FILEATRB* atr)
49104924
{
@@ -4952,6 +4966,7 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49524966
WOLFSSH_UNUSED(handleSz);
49534967
return WS_SUCCESS;
49544968
}
4969+
#endif /* !NO_WOLFSSH_SERVER */
49554970

49564971
#elif defined(WOLFSSH_ZEPHYR)
49574972

@@ -4991,6 +5006,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49915006
return PopulateAttributes(atr, &stats);
49925007
}
49935008

5009+
#ifndef NO_WOLFSSH_SERVER
49945010
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
49955011
char* name, WS_SFTP_FILEATRB* atr)
49965012
{
@@ -5003,6 +5019,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
50035019
WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
50045020
return WS_NOT_COMPILED;
50055021
}
5022+
#endif /* !NO_WOLFSSH_SERVER */
50065023

50075024
#elif defined(MICROCHIP_MPLAB_HARMONY)
50085025
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
@@ -5090,11 +5107,13 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50905107
* Fills out a WS_SFTP_FILEATRB structure
50915108
* returns WS_SUCCESS on success
50925109
*/
5110+
#ifndef NO_WOLFSSH_SERVER
50935111
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
50945112
char* name, WS_SFTP_FILEATRB* atr)
50955113
{
50965114
return SFTP_GetAttributesHelper(atr, name);
50975115
}
5116+
#endif /* !NO_WOLFSSH_SERVER */
50985117

50995118
#else
51005119

@@ -5147,6 +5166,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
51475166
}
51485167

51495168

5169+
#ifndef NO_WOLFSSH_SERVER
51505170
/* @TODO can be overridden by user for portability
51515171
* Gets attributes based on file descriptor
51525172
* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -5191,8 +5211,10 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
51915211
WOLFSSH_UNUSED(name);
51925212
return WS_SUCCESS;
51935213
}
5214+
#endif /* !NO_WOLFSSH_SERVER */
51945215
#endif
51955216

5217+
#ifndef NO_WOLFSSH_SERVER
51965218

51975219
#ifndef USE_WINDOWS_API
51985220
/* Handles receiving fstat packet
@@ -9316,7 +9338,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
93169338
ret = SFTP_FreeHandles(ssh);
93179339
#endif
93189340

9319-
#ifndef NO_WOLFSSH_DIR
9341+
#if !defined(NO_WOLFSSH_DIR) && !defined(NO_WOLFSSH_SERVER)
93209342
{
93219343
/* free all dirs if hung up on */
93229344
WS_DIR_LIST* cur = ssh->dirList;
@@ -9337,7 +9359,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
93379359
}
93389360
ssh->dirList = NULL;
93399361
}
9340-
#endif /* NO_WOLFSSH_DIR */
9362+
#endif /* !NO_WOLFSSH_DIR && !NO_WOLFSSH_SERVER */
93419363

93429364
wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
93439365
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)