From 092c04fe302f6f5f40f637d71b95cc71d6cea395 Mon Sep 17 00:00:00 2001 From: Fabio Alemagna <507164+falemagn@users.noreply.github.com> Date: Fri, 21 Jul 2023 07:46:02 +0200 Subject: [PATCH] All the filesystem-related W* macros accept a filesystem context pointer as first parameter, to make portability better. --- apps/wolfsshd/configuration.c | 8 +- apps/wolfsshd/test/test_configuration.c | 10 +- apps/wolfsshd/wolfsshd.c | 16 +-- examples/client/common.c | 18 +-- examples/echoserver/echoserver.c | 6 +- examples/server/server.c | 2 +- src/port.c | 4 +- src/ssh.c | 20 +-- src/wolfscp.c | 99 +++++++------- src/wolfsftp.c | 48 +++---- wolfssh/port.h | 166 ++++++++++++------------ wolfssh/test.h | 4 +- 12 files changed, 206 insertions(+), 195 deletions(-) diff --git a/apps/wolfsshd/configuration.c b/apps/wolfsshd/configuration.c index 71d2d5de6..fd2852818 100644 --- a/apps/wolfsshd/configuration.c +++ b/apps/wolfsshd/configuration.c @@ -658,7 +658,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value) char** fileNames = NULL; /* Count up the number of files */ - while ((dir = WREADDIR(&d)) != NULL) { + while ((dir = WREADDIR(NULL, &d)) != NULL) { /* Skip sub-directories */ #if defined(__QNX__) || defined(__QNXNTO__) struct stat s; @@ -672,7 +672,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value) fileCount++; } } - WREWINDDIR(&d); + WREWINDDIR(NULL, &d); if (fileCount > 0) { fileNames = (char**)WMALLOC(fileCount * sizeof(char*), @@ -684,7 +684,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value) if (ret == WS_SUCCESS) { i = 0; - while (i < fileCount && (dir = WREADDIR(&d)) != NULL) { + while (i < fileCount && (dir = WREADDIR(NULL, &d)) != NULL) { /* Skip sub-directories */ #if defined(__QNX__) || defined(__QNXNTO__) struct stat s; @@ -752,7 +752,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value) WFREE(fileNames, conf->heap, DYNTYPE_PATH); } } - WCLOSEDIR(&d); + WCLOSEDIR(NULL, &d); } else { /* Bad directory */ diff --git a/apps/wolfsshd/test/test_configuration.c b/apps/wolfsshd/test/test_configuration.c index 1528731ec..4c1000e23 100644 --- a/apps/wolfsshd/test/test_configuration.c +++ b/apps/wolfsshd/test/test_configuration.c @@ -33,7 +33,7 @@ static void CleanupWildcardTest(void) char filepath[MAX_PATH*2]; /* d_name is max_path long */ if (!WOPENDIR(NULL, NULL, &dir, "./sshd_config.d/")) { - while ((d = WREADDIR(&dir)) != NULL) { + while ((d = WREADDIR(NULL, &dir)) != NULL) { #if defined(__QNX__) || defined(__QNXNTO__) struct stat s; @@ -48,7 +48,7 @@ static void CleanupWildcardTest(void) WREMOVE(0, filepath); } } - WCLOSEDIR(&dir); + WCLOSEDIR(NULL, &dir); WRMDIR(0, "./sshd_config.d/"); } } @@ -75,15 +75,15 @@ static int SetupWildcardTest(void) "./sshd_config.d/"); } - WFOPEN(&f, filepath, "w"); + WFOPEN(NULL, &f, filepath, "w"); if (f) { word32 sz, wr; char contents[20]; WSNPRINTF(contents, sizeof contents, "LoginGraceTime %02u", fileIds[i]); sz = (word32)WSTRLEN(contents); - wr = (word32)WFWRITE(contents, sizeof(char), sz, f); - WFCLOSE(f); + wr = (word32)WFWRITE(NULL, contents, sizeof(char), sz, f); + WFCLOSE(NULL, f); if (sz != wr) { Log("Couldn't write the contents of file %s\n", filepath); ret = WS_FATAL_ERROR; diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 4991b62dc..6ff992734 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -207,22 +207,22 @@ static byte* getBufferFromFile(const char* fileName, word32* bufSz, void* heap) if (fileName == NULL) return NULL; - if (WFOPEN(&file, fileName, "rb") != 0) + if (WFOPEN(NULL, &file, fileName, "rb") != 0) return NULL; - WFSEEK(file, 0, XSEEK_END); - fileSz = (word32)WFTELL(file); - WREWIND(file); + WFSEEK(NULL, file, 0, XSEEK_END); + fileSz = (word32)WFTELL(NULL, file); + WREWIND(NULL, file); buf = (byte*)WMALLOC(fileSz + 1, heap, DYNTYPE_SSHD); if (buf != NULL) { - readSz = (word32)WFREAD(buf, 1, fileSz, file); + readSz = (word32)WFREAD(NULL, buf, 1, fileSz, file); if (readSz < fileSz) { - WFCLOSE(file); + WFCLOSE(NULL, file); WFREE(buf, heap, DYNTYPE_SSHD); return NULL; } *bufSz = readSz; - WFCLOSE(file); + WFCLOSE(NULL, file); } (void)heap; @@ -573,7 +573,7 @@ static int SFTP_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, "[SSHD] Error setting SFTP default home path"); ret = WS_FATAL_ERROR; } - WCLOSEDIR(&dir); + WCLOSEDIR(NULL, &dir); } } diff --git a/examples/client/common.c b/examples/client/common.c index d66603ca3..6e48a4b67 100644 --- a/examples/client/common.c +++ b/examples/client/common.c @@ -248,29 +248,29 @@ static int load_der_file(const char* filename, byte** out, word32* outSz) if (filename == NULL || out == NULL || outSz == NULL) return -1; - ret = WFOPEN(&file, filename, "rb"); + ret = WFOPEN(NULL, &file, filename, "rb"); if (ret != 0 || file == WBADFILE) return -1; - if (WFSEEK(file, 0, WSEEK_END) != 0) { - WFCLOSE(file); + if (WFSEEK(NULL, file, 0, WSEEK_END) != 0) { + WFCLOSE(NULL, file); return -1; } - inSz = (word32)WFTELL(file); - WREWIND(file); + inSz = (word32)WFTELL(NULL, file); + WREWIND(NULL, file); if (inSz == 0) { - WFCLOSE(file); + WFCLOSE(NULL, file); return -1; } in = (byte*)WMALLOC(inSz, NULL, 0); if (in == NULL) { - WFCLOSE(file); + WFCLOSE(NULL, file); return -1; } - ret = (int)WFREAD(in, 1, inSz, file); + ret = (int)WFREAD(NULL, in, 1, inSz, file); if (ret <= 0 || (word32)ret != inSz) { ret = -1; WFREE(in, NULL, 0); @@ -283,7 +283,7 @@ static int load_der_file(const char* filename, byte** out, word32* outSz) *out = in; *outSz = inSz; - WFCLOSE(file); + WFCLOSE(NULL, file); return ret; } diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index ebff84394..ab1338e0d 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -1411,7 +1411,7 @@ static int load_file(const char* fileName, byte* buf, word32* bufSz) if (fileName == NULL) return 0; - if (WFOPEN(&file, fileName, "rb") != 0) + if (WFOPEN(NULL, &file, fileName, "rb") != 0) return 0; fseek(file, 0, XSEEK_END); fileSz = (word32)ftell(file); @@ -2511,10 +2511,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) #ifndef NO_FILESYSTEM WFILE* f = NULL; int ret; - ret = WFOPEN(&f, readyFile, "w"); + ret = WFOPEN(NULL, &f, readyFile, "w"); if (f != NULL && ret == 0) { fprintf(f, "%d\n", (int)port); - WFCLOSE(f); + WFCLOSE(NULL, f); } #endif } diff --git a/examples/server/server.c b/examples/server/server.c index abdcb891f..1136d0135 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -282,7 +282,7 @@ static int load_file(const char* fileName, byte* buf, word32 bufSz) if (fileName == NULL) return 0; - if (WFOPEN(&file, fileName, "rb") != 0) + if (WFOPEN(NULL, &file, fileName, "rb") != 0) return 0; fseek(file, 0, SEEK_END); fileSz = (word32)ftell(file); diff --git a/src/port.c b/src/port.c index f8d6c0462..543c6dbb0 100644 --- a/src/port.c +++ b/src/port.c @@ -66,13 +66,13 @@ int wfopen(WFILE** f, const char* filename, const char* mode) } if (filename != NULL && f != NULL) { - if ((**f = WOPEN(filename, m, 0)) < 0) { + if ((**f = WOPEN(ssh->fs, filename, m, 0)) < 0) { return **f; } /* fopen defaults to normal */ if (NU_Set_Attributes(filename, 0) != NU_SUCCESS) { - WCLOSE(**f); + WCLOSE(ssh->fs, **f); return 1; } return 0; diff --git a/src/ssh.c b/src/ssh.c index 2db5e340c..cc7ce7c90 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -1534,7 +1534,7 @@ int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, int format, } -#ifndef NO_FILESYSTEM +#if !defined(NO_FILESYSTEM) && !defined(WOLFSSH_USER_FILESYSTEM) /* Reads a key from the file name into a buffer. If the key starts with the string "ssh-rsa" or "ecdsa-sha2-nistp256", it is considered an SSH format @@ -1557,27 +1557,27 @@ int wolfSSH_ReadKey_file(const char* name, isPrivate == NULL) return WS_BAD_ARGUMENT; - ret = WFOPEN(&file, name, "rb"); + ret = WFOPEN(NULL, &file, name, "rb"); if (ret != 0 || file == WBADFILE) return WS_BAD_FILE_E; - if (WFSEEK(file, 0, WSEEK_END) != 0) { - WFCLOSE(file); + if (WFSEEK(NULL, file, 0, WSEEK_END) != 0) { + WFCLOSE(NULL, file); return WS_BAD_FILE_E; } - inSz = (word32)WFTELL(file); - WREWIND(file); + inSz = (word32)WFTELL(NULL, file); + WREWIND(NULL, file); if (inSz > WOLFSSH_MAX_FILE_SIZE || inSz == 0) { - WFCLOSE(file); + WFCLOSE(NULL, file); return WS_BAD_FILE_E; } in = (byte*)WMALLOC(inSz + 1, heap, DYNTYPE_FILE); if (in == NULL) { - WFCLOSE(file); + WFCLOSE(NULL, file); return WS_MEMORY_E; } - ret = (int)WFREAD(in, 1, inSz, file); + ret = (int)WFREAD(NULL, in, 1, inSz, file); if (ret <= 0 || (word32)ret != inSz) { ret = WS_BAD_FILE_E; } @@ -1599,7 +1599,7 @@ int wolfSSH_ReadKey_file(const char* name, out, outSz, outType, outTypeSz, heap); } - WFCLOSE(file); + WFCLOSE(ssh->fs, file); WFREE(in, heap, DYNTYPE_FILE); return ret; diff --git a/src/wolfscp.c b/src/wolfscp.c index f3db331ef..55c42d042 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -53,8 +53,8 @@ #ifndef NO_FILESYSTEM static int ScpFileIsDir(ScpSendCtx* ctx); -static int ScpPushDir(ScpSendCtx* ctx, const char* path, void* heap); -static int ScpPopDir(ScpSendCtx* ctx, void* heap); +static int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap); +static int ScpPopDir(void *fs, ScpSendCtx* ctx, void* heap); #endif const char scpError[] = "scp error: %s, %d"; @@ -1165,11 +1165,12 @@ static int ParseBasePathHelper(WOLFSSH* ssh, int cmdSz) ScpSendCtx ctx; WMEMSET(&ctx, 0, sizeof(ScpSendCtx)); - if (ScpPushDir(&ctx, ssh->scpBasePath, ssh->ctx->heap) != WS_SUCCESS) { + + if (ScpPushDir(ssh->fs, &ctx, ssh->scpBasePath, ssh->ctx->heap) != WS_SUCCESS) { WLOG(WS_LOG_DEBUG, "scp : issue opening base dir"); } else { - ret = ScpPopDir(&ctx, ssh->ctx->heap); + ret = ScpPopDir(ssh->fs, &ctx, ssh->ctx->heap); if (ret == WS_SCP_DIR_STACK_EMPTY_E) { ret = WS_SUCCESS; /* is ok to empty the directory stack here */ } @@ -1910,7 +1911,7 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, } } #else - if (WCHDIR(basePath) != 0) { + if (WCHDIR(ssh->fs, basePath) != 0) { WLOG(WS_LOG_ERROR, "scp: invalid destination directory, abort"); wolfSSH_SetScpErrorMsg(ssh, "invalid destination directory"); @@ -1928,9 +1929,9 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, WSTRNCAT(abslut, "/", WOLFSSH_MAX_FILENAME); WSTRNCAT(abslut, fileName, WOLFSSH_MAX_FILENAME); wolfSSH_CleanPath(ssh, abslut); - if (WFOPEN(&fp, abslut, "wb") != 0) { + if (WFOPEN(ssh->fs, &fp, abslut, "wb") != 0) { #else - if (WFOPEN(&fp, fileName, "wb") != 0) { + if (WFOPEN(ssh->fs, &fp, fileName, "wb") != 0) { #endif WLOG(WS_LOG_ERROR, "scp: unable to open file for writing, abort"); @@ -1954,11 +1955,11 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, break; } /* read file, or file part */ - bytes = (word32)WFWRITE(buf, 1, bufSz, fp); + bytes = (word32)WFWRITE(ssh->fs, buf, 1, bufSz, fp); if (bytes != bufSz) { WLOG(WS_LOG_ERROR, scpError, "scp receive callback unable " "to write requested size to file", bytes); - WFCLOSE(fp); + WFCLOSE(ssh->fs, fp); ret = WS_SCP_ABORT; } else { #ifdef WOLFSCP_FLUSH @@ -1984,7 +1985,7 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, (void)fsync(fileno(fp)); flush_bytes = 0; #endif - WFCLOSE(fp); + WFCLOSE(ssh->fs, fp); } /* set timestamp info */ @@ -2041,7 +2042,7 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, WSTRNCAT((char*)basePath, fileName, WOLFSSH_MAX_FILENAME); wolfSSH_CleanPath(ssh, (char*)basePath); #else - if (WCHDIR(fileName) != 0) { + if (WCHDIR(ssh->fs, fileName) != 0) { WLOG(WS_LOG_ERROR, "scp: unable to cd into direcotry, abort"); wolfSSH_SetScpErrorMsg(ssh, "unable to cd into directory"); @@ -2058,7 +2059,7 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, WSTRNCAT((char*)basePath, "/..", WOLFSSH_MAX_FILENAME - 1); wolfSSH_CleanPath(ssh, (char*)basePath); #else - if (WCHDIR("..") != 0) { + if (WCHDIR(ssh->fs, "..") != 0) { WLOG(WS_LOG_ERROR, "scp: unable to cd out of direcotry, abort"); wolfSSH_SetScpErrorMsg(ssh, "unable to cd out of directory"); @@ -2079,23 +2080,27 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, return ret; } -static int GetFileSize(WFILE* fp, word32* fileSz) +static int GetFileSize(void *fs, WFILE* fp, word32* fileSz) { + WOLFSSH_UNUSED(fs); + if (fp == NULL || fileSz == NULL) return WS_BAD_ARGUMENT; /* get file size */ - WFSEEK(fp, 0, WSEEK_END); - *fileSz = (word32)WFTELL(fp); - WREWIND(fp); + WFSEEK(fs, fp, 0, WSEEK_END); + *fileSz = (word32)WFTELL(fs, fp); + WREWIND(fs, fp); return WS_SUCCESS; } -static int GetFileStats(ScpSendCtx* ctx, const char* fileName, +static int GetFileStats(void *fs, ScpSendCtx* ctx, const char* fileName, word64* mTime, word64* aTime, int* fileMode) { int ret = WS_SUCCESS; + + WOLFSSH_UNUSED(fs); if (ctx == NULL || fileName == NULL || mTime == NULL || aTime == NULL || fileMode == NULL) { @@ -2103,7 +2108,7 @@ static int GetFileStats(ScpSendCtx* ctx, const char* fileName, } /* get file stats for times and mode */ - if (WSTAT(fileName, &ctx->s) < 0) { + if (WSTAT(fs, fileName, &ctx->s) < 0) { ret = WS_BAD_FILE_E; #ifdef WOLFSSL_NUCLEUS if (WSTRLEN(fileName) < 4 && WSTRLEN(fileName) > 2 && @@ -2138,8 +2143,10 @@ static int GetFileStats(ScpSendCtx* ctx, const char* fileName, /* Create new ScpDir struct for pushing on directory stack. * Return valid pointer on success, NULL on failure */ -static ScpDir* ScpNewDir(const char* path, void* heap) +static ScpDir* ScpNewDir(void *fs, const char* path, void* heap) { + WOLFSSH_UNUSED(fs); + ScpDir* entry = NULL; if (path == NULL) { @@ -2155,7 +2162,7 @@ static ScpDir* ScpNewDir(const char* path, void* heap) } entry->next = NULL; - if (WOPENDIR(NULL, heap, &entry->dir, path) != 0 + if (WOPENDIR(fs, heap, &entry->dir, path) != 0 #ifndef WOLFSSL_NUCLEUS || entry->dir == NULL #endif @@ -2170,14 +2177,14 @@ static ScpDir* ScpNewDir(const char* path, void* heap) } /* Create and push new ScpDir on stack, append directory to ctx->dirName */ -int ScpPushDir(ScpSendCtx* ctx, const char* path, void* heap) +int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap) { ScpDir* entry; if (ctx == NULL || path == NULL) return WS_BAD_ARGUMENT; - entry = ScpNewDir(path, heap); + entry = ScpNewDir(fs, path, heap); if (entry == NULL) { return WS_FATAL_ERROR; } @@ -2198,8 +2205,10 @@ int ScpPushDir(ScpSendCtx* ctx, const char* path, void* heap) } /* Remove top ScpDir from directory stack, remove dir from ctx->dirName */ -int ScpPopDir(ScpSendCtx* ctx, void* heap) +int ScpPopDir(void *fs, ScpSendCtx* ctx, void* heap) { + WOLFSSH_UNUSED(fs); + ScpDir* entry = NULL; int idx = 0, separator = 0; @@ -2209,7 +2218,7 @@ int ScpPopDir(ScpSendCtx* ctx, void* heap) } if (entry != NULL) { - WCLOSEDIR(&entry->dir); + WCLOSEDIR(fs, &entry->dir); WFREE(entry, heap, DYNTYPE_SCPDIR); } @@ -2235,8 +2244,10 @@ int ScpPopDir(ScpSendCtx* ctx, void* heap) /* Get next entry in directory, either file or directory, skips self (.) * and parent (..) directories, stores in ctx->entry. * Return WS_SUCCESS on success or negative upon error */ -static int FindNextDirEntry(ScpSendCtx* ctx) +static int FindNextDirEntry(void *fs, ScpSendCtx* ctx) { + WOLFSSH_UNUSED(fs); + if (ctx == NULL) return WS_BAD_ARGUMENT; @@ -2259,7 +2270,7 @@ static int FindNextDirEntry(ScpSendCtx* ctx) if (ctx->nextError == 1) { WDIR* dr; do { - dr = WREADDIR(&ctx->currentDir->dir); + dr = WREADDIR(fs, &ctx->currentDir->dir); } while (dr != NULL && (WSTRNCMP(ctx->currentDir->dir.lfname, ".", 1) == 0 || WSTRNCMP(ctx->currentDir->dir.lfname ,"..", 2) == 0)); @@ -2270,7 +2281,7 @@ static int FindNextDirEntry(ScpSendCtx* ctx) ctx->nextError = 1; #else do { - ctx->entry = WREADDIR(&ctx->currentDir->dir); + ctx->entry = WREADDIR(fs, &ctx->currentDir->dir); } while ((ctx->entry != NULL) && (WSTRNCMP(ctx->entry->d_name, ".", 1) == 0 || WSTRNCMP(ctx->entry->d_name ,"..", 2) == 0)); @@ -2361,7 +2372,7 @@ static int ScpProcessEntry(WOLFSSH* ssh, char* fileName, word64* mTime, DEFAULT_SCP_FILE_NAME_SZ); #endif if (ret == WS_SUCCESS) { - ret = GetFileStats(sendCtx, filePath, mTime, aTime, fileMode); + ret = GetFileStats(ssh->fs, sendCtx, filePath, mTime, aTime, fileMode); } } } @@ -2370,7 +2381,7 @@ static int ScpProcessEntry(WOLFSSH* ssh, char* fileName, word64* mTime, if (ScpFileIsDir(sendCtx)) { - ret = ScpPushDir(sendCtx, filePath, ssh->ctx->heap); + ret = ScpPushDir(ssh->fs, sendCtx, filePath, ssh->ctx->heap); if (ret == WS_SUCCESS) { ret = WS_SCP_ENTER_DIR; } else { @@ -2379,7 +2390,7 @@ static int ScpProcessEntry(WOLFSSH* ssh, char* fileName, word64* mTime, } } else if (ScpFileIsFile(sendCtx)) { - if (WFOPEN(&(sendCtx->fp), filePath, "rb") != 0) { + if (WFOPEN(ssh->fs, &(sendCtx->fp), filePath, "rb") != 0) { WLOG(WS_LOG_ERROR, "scp: Error with oepning file, abort"); wolfSSH_SetScpErrorMsg(ssh, "unable to open file " "for reading"); @@ -2387,16 +2398,16 @@ static int ScpProcessEntry(WOLFSSH* ssh, char* fileName, word64* mTime, } if (ret == WS_SUCCESS) { - ret = GetFileSize(sendCtx->fp, totalFileSz); + ret = GetFileSize(ssh->fs, sendCtx->fp, totalFileSz); if (ret == WS_SUCCESS) - ret = (word32)WFREAD(buf, 1, bufSz, sendCtx->fp); + ret = (word32)WFREAD(ssh->fs, buf, 1, bufSz, sendCtx->fp); } /* keep fp open if no errors and transfer will continue */ if ((sendCtx->fp != NULL) && ((ret < 0) || (*totalFileSz == (word32)ret))) { - WFCLOSE(sendCtx->fp); + WFCLOSE(ssh->fs, sendCtx->fp); } } @@ -2519,7 +2530,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, break; case WOLFSSH_SCP_SINGLE_FILE_REQUEST: - if ((sendCtx == NULL) || WFOPEN(&(sendCtx->fp), peerRequest, + if ((sendCtx == NULL) || WFOPEN(ssh->fs, &(sendCtx->fp), peerRequest, "rb") != 0) { WLOG(WS_LOG_ERROR, "scp: unable to open file, abort"); @@ -2538,10 +2549,10 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, } if (ret == WS_SUCCESS) - ret = GetFileSize(sendCtx->fp, totalFileSz); + ret = GetFileSize(ssh->fs, sendCtx->fp, totalFileSz); if (ret == WS_SUCCESS) - ret = GetFileStats(sendCtx, peerRequest, mTime, aTime, fileMode); + ret = GetFileStats(ssh->fs, sendCtx, peerRequest, mTime, aTime, fileMode); if (ret == WS_SUCCESS) ret = ExtractFileName(peerRequest, fileName, fileNameSz); @@ -2549,7 +2560,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, if (ret == WS_SUCCESS && sendCtx != NULL && sendCtx->fp != NULL) { /* If it is an empty file, do not read. */ if (*totalFileSz != 0) { - ret = (word32)WFREAD(buf, 1, bufSz, sendCtx->fp); + ret = (word32)WFREAD(ssh->fs, buf, 1, bufSz, sendCtx->fp); if (ret == 0) { /* handle unexpected case */ ret = WS_EOF; } @@ -2562,7 +2573,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, /* keep fp open if no errors and transfer will continue */ if ((sendCtx != NULL) && (sendCtx->fp != NULL) && ((ret < 0) || (*totalFileSz == (word32)ret))) { - WFCLOSE(sendCtx->fp); + WFCLOSE(ssh->fs, sendCtx->fp); } break; @@ -2572,7 +2583,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, if (ScpDirStackIsEmpty(sendCtx)) { /* first request, keep track of request directory */ - ret = ScpPushDir(sendCtx, peerRequest, ssh->ctx->heap); + ret = ScpPushDir(ssh->fs, sendCtx, peerRequest, ssh->ctx->heap); if (ret == WS_SUCCESS) { /* get file name from request */ @@ -2580,7 +2591,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, } if (ret == WS_SUCCESS) { - ret = GetFileStats(sendCtx, peerRequest, mTime, aTime, + ret = GetFileStats(ssh->fs, sendCtx, peerRequest, mTime, aTime, fileMode); } @@ -2595,7 +2606,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, /* send directory msg or abort */ break; } - ret = FindNextDirEntry(sendCtx); + ret = FindNextDirEntry(ssh->fs, sendCtx); /* help out static analysis tool */ if (ret != WS_BAD_ARGUMENT && sendCtx == NULL) @@ -2609,7 +2620,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, /* reached end of directory */ if (sendCtx->entry == NULL) { #endif - ret = ScpPopDir(sendCtx, ssh->ctx->heap); + ret = ScpPopDir(ssh->fs, sendCtx, ssh->ctx->heap); if (ret == WS_SUCCESS) { ret = WS_SCP_EXIT_DIR; @@ -2645,13 +2656,13 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, break; } - ret = (word32)WFREAD(buf, 1, bufSz, sendCtx->fp); + ret = (word32)WFREAD(ssh->fs, buf, 1, bufSz, sendCtx->fp); if (ret == 0) { /* handle case of EOF */ ret = WS_EOF; } if ((ret <= 0) || (fileOffset + ret == *totalFileSz)) { - WFCLOSE(sendCtx->fp); + WFCLOSE(ssh->fs, sendCtx->fp); } break; diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 47a2ac43a..253c9be26 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -1961,7 +1961,7 @@ int wolfSSH_SFTP_RecvOpen(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) atr.per = 0644; } - fd = WOPEN(dir, m, atr.per); + fd = WOPEN(ssh->fs, dir, m, atr.per); if (fd < 0) { WLOG(WS_LOG_SFTP, "Error opening file %s", dir); res = oer; @@ -2215,14 +2215,14 @@ int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) cur = (DIR_HANDLE*)WMALLOC(sizeof(DIR_HANDLE), ssh->ctx->heap, DYNTYPE_SFTP); if (cur == NULL) { - WCLOSEDIR(&ctx); + WCLOSEDIR(ssh->fs, &ctx); return WS_MEMORY_E; } dirNameSz = (word32)WSTRLEN(dir) + 1; dirName = (char*)WMALLOC(dirNameSz, ssh->ctx->heap, DYNTYPE_PATH); if (dirName == NULL) { - WCLOSEDIR(&ctx); + WCLOSEDIR(ssh->fs, &ctx); WFREE(cur, ssh->ctx->heap, DYNTYPE_SFTP); return WS_MEMORY_E; } @@ -2613,7 +2613,7 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, } } - if (!special && (WREADDIR(dir)) == NULL) { + if (!special && (WREADDIR(ssh->fs, dir)) == NULL) { ret = WS_NEXT_ERROR; } @@ -2887,7 +2887,7 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out, return WS_BAD_ARGUMENT; } - dp = WREADDIR(dir); + dp = WREADDIR(ssh->fs, dir); if (dp == NULL) { return WS_FATAL_ERROR; } @@ -3164,7 +3164,7 @@ int wolfSSH_SFTP_RecvCloseDir(WOLFSSH* ssh, byte* handle, word32 handleSz) #ifdef USE_WINDOWS_API FindClose(cur->dir); #else - WCLOSEDIR(&cur->dir); + WCLOSEDIR(ssh->fs, &cur->dir); #endif /* remove directory from list */ @@ -3247,7 +3247,7 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) return WS_BUFFER_E; } - ret = WPWRITE(fd, data + idx, sz, ofst); + ret = WPWRITE(ssh->fs, fd, data + idx, sz, ofst); if (ret < 0) { #if defined(WOLFSSL_NUCLEUS) && defined(DEBUG_WOLFSSH) if (ret == NUF_NOSPC) { @@ -3424,7 +3424,7 @@ int wolfSSH_SFTP_RecvRead(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) return WS_MEMORY_E; } - ret = WPREAD(fd, out + UINT32_SZ + WOLFSSH_SFTP_HEADER, sz, ofst); + ret = WPREAD(ssh->fs, fd, out + UINT32_SZ + WOLFSSH_SFTP_HEADER, sz, ofst); if (ret < 0 || (word32)ret > sz) { WLOG(WS_LOG_SFTP, "Error reading from file"); res = err; @@ -3627,7 +3627,7 @@ int wolfSSH_SFTP_RecvClose(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) if (sz == sizeof(WFD)) { WMEMSET((byte*)&fd, 0, sizeof(WFD)); WMEMCPY((byte*)&fd, data + idx, sz); - ret = WCLOSE(fd); + ret = WCLOSE(ssh->fs, fd); #ifdef WOLFSSH_STOREHANDLE if (SFTP_RemoveHandleNode(ssh, data + idx, sz) != WS_SUCCESS) { WLOG(WS_LOG_SFTP, "Unable to remove handle from list"); @@ -4085,10 +4085,10 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr, WOLFSSH_UNUSED(fs); if (noFollow) { - ret = WLSTAT(fileName, &stats); + ret = WLSTAT(ssh->fs, fileName, &stats); } else { - ret = WSTAT(fileName, &stats); + ret = WSTAT(ssh->fs, fileName, &stats); } WMEMSET(atr, 0, sizeof(WS_SFTP_FILEATRB)); @@ -4167,7 +4167,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz, return WS_BAD_FILE_E; } - if (WSTAT(cur->name, &stats) != NU_SUCCESS) { + if (WSTAT(ssh->fs, cur->name, &stats) != NU_SUCCESS) { return WS_FATAL_ERROR; } @@ -4507,12 +4507,12 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr, if (noFollow) { /* Note, for windows, we treat WSTAT and WLSTAT the same. */ - if (WLSTAT(fileName, &stats) != 0) { + if (WLSTAT(ssh->fs, fileName, &stats) != 0) { return WS_BAD_FILE_E; } } else { - if (WSTAT(fileName, &stats) != 0) { + if (WSTAT(ssh->fs, fileName, &stats) != 0) { return WS_BAD_FILE_E; } } @@ -8098,9 +8098,9 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, WLOG(WS_LOG_SFTP, "SFTP GET STATE: OPEN LOCAL"); #ifndef USE_WINDOWS_API if (state->gOfst[0] > 0 || state->gOfst[1] > 0) - ret = WFOPEN(&state->fl, to, "ab"); + ret = WFOPEN(ssh->fs, &state->fl, to, "ab"); else - ret = WFOPEN(&state->fl, to, "wb"); + ret = WFOPEN(ssh->fs, &state->fl, to, "wb"); #else /* USE_WINDOWS_API */ { DWORD desiredAccess = GENERIC_WRITE; @@ -8145,7 +8145,7 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, } else { #ifndef USE_WINDOWS_API - if ((long)WFWRITE(state->r, 1, + if ((long)WFWRITE(ssh->fs, state->r, 1, sz, state->fl) != sz) { WLOG(WS_LOG_SFTP, "Error writing to file"); ssh->error = WS_BAD_FILE_E; @@ -8207,7 +8207,7 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, case STATE_GET_CLOSE_LOCAL: WLOG(WS_LOG_SFTP, "SFTP GET STATE: CLOSE LOCAL"); #ifndef USE_WINDOWS_API - WFCLOSE(state->fl); + WFCLOSE(ssh->fs, state->fl); #else /* USE_WINDOWS_API */ if (CloseHandle(state->fileHandle) == 0) { WLOG(WS_LOG_SFTP, "Error closing file."); @@ -8296,7 +8296,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, case STATE_PUT_OPEN_LOCAL: WLOG(WS_LOG_SFTP, "SFTP PUT STATE: OPEN LOCAL"); #ifndef USE_WINDOWS_API - ret = WFOPEN(&state->fl, from, "rb"); + ret = WFOPEN(ssh->fs, &state->fl, from, "rb"); if (ret != 0) { WLOG(WS_LOG_SFTP, "Unable to open input file"); ssh->error = WS_SFTP_FILE_DNE; @@ -8310,7 +8310,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, #if SIZEOF_OFF_T == 8 offset = (((word64)state->pOfst[1]) << 32) | offset; #endif - WFSEEK(state->fl, offset, 0); + WFSEEK(ssh->fs, state->fl, offset, 0); } #else /* USE_WINDOWS_API */ state->fileHandle = WS_CreateFileA(from, GENERIC_READ, @@ -8355,7 +8355,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, do { if (state->rSz == 0) { #ifndef USE_WINDOWS_API - state->rSz = (int)WFREAD(state->r, + state->rSz = (int)WFREAD(ssh->fs, state->r, 1, WOLFSSH_MAX_SFTP_RW, state->fl); if (state->rSz <= 0) { break; /* either at end of file or error */ @@ -8399,7 +8399,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, case STATE_PUT_CLOSE_LOCAL: WLOG(WS_LOG_SFTP, "SFTP PUT STATE: CLOSE LOCAL"); #ifndef USE_WINDOWS_API - WFCLOSE(state->fl); + WFCLOSE(ssh->fs, state->fl); #else /* USE_WINDOWS_API */ CloseHandle(state->fileHandle); #endif /* USE_WINDOWS_API */ @@ -8450,7 +8450,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh) /* go through and free handles and make sure files are closed */ while (cur != NULL) { - WCLOSE(*((WFD*)cur->handle)); + WCLOSE(ssh->fs, *((WFD*)cur->handle)); if (SFTP_RemoveHandleNode(ssh, cur->handle, cur->handleSz) != WS_SUCCESS) { return WS_FATAL_ERROR; @@ -8473,7 +8473,7 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh) #ifdef USE_WINDOWS_API FindClose(toFree->dir); #else - WCLOSEDIR(&toFree->dir); + WCLOSEDIR(ssh->fs, &toFree->dir); #endif if (toFree->dirName != NULL) WFREE(toFree->dirName, ssh->ctx->heap, DYNTYPE_SFTP); diff --git a/wolfssh/port.h b/wolfssh/port.h index ddbd7ed11..485ed0fbd 100644 --- a/wolfssh/port.h +++ b/wolfssh/port.h @@ -99,14 +99,14 @@ extern "C" { #define WFILE int WOLFSSH_API int wfopen(WFILE**, const char*, const char*); - #define WFOPEN(f,fn,m) wfopen((f),(fn),(m)) - #define WFCLOSE(f) NU_Close(*(f)) - #define WFWRITE(b,x,s,f) ((s) != 0)? NU_Write(*(f),(const CHAR*)(b),(s)): 0 - #define WFREAD(b,x,s,f) NU_Read(*(f),(CHAR*)(b),(s)) - #define WFSEEK(s,o,w) NU_Seek(*(s),(o),(w)) - #define WFTELL(s) NU_Seek(*(s), 0, PSEEK_CUR) - #define WREWIND(s) NU_Seek(*(s), 0, PSEEK_SET) - #define WSEEK_END PSEEK_END + #define WFOPEN(fs, f,fn,m) wfopen((f),(fn),(m)) + #define WFCLOSE(fs,f) NU_Close(*(f)) + #define WFWRITE(fs,b,x,s,f) ((s) != 0)? NU_Write(*(f),(const CHAR*)(b),(s)): 0 + #define WFREAD(fs,b,x,s,f) NU_Read(*(f),(CHAR*)(b),(s)) + #define WFSEEK(fs,s,o,w) NU_Seek(*(s),(o),(w)) + #define WFTELL(fs,s) NU_Seek(*(s), 0, PSEEK_CUR) + #define WREWIND(fs,s) NU_Seek(*(s), 0, PSEEK_SET) + #define WSEEK_END PSEEK_END #define WS_DELIM '\\' #define WOLFSSH_O_RDWR PO_RDWR @@ -124,10 +124,10 @@ extern "C" { return NU_Open(f, PO_TEXT | flag, (PS_IWRITE | PS_IREAD)); } - #define WOPEN(f,m,p) wOpen((f),(m),(p)) + #define WOPEN(fs,f,m,p) wOpen((f),(m),(p)) #endif - #define WCLOSE(fd) NU_Close((fd)) + #define WCLOSE(fs,fd) NU_Close((fd)) static inline int wChmod(const char* f, int mode) { unsigned char atr = 0; @@ -176,13 +176,13 @@ extern "C" { WOLFSSH_API int wfopen(WFILE**, const char*, const char*); - #define WFOPEN(f,fn,m) wfopen((f),(fn),(m)) - #define WFCLOSE(f) fclose((f)) - #define WFREAD(b,s,a,f) fread((b),(s),(a),(f)) - #define WFWRITE(b,x,s,f) fwrite((b),(x),(s),(f)) - #define WFSEEK(s,o,w) fseek((s),(o),(w)) - #define WFTELL(s) ftell((s)) - #define WREWIND(s) fseek((s), 0, IO_SEEK_SET) + #define WFOPEN(fs,f,fn,m) wfopen((f),(fn),(m)) + #define WFCLOSE(fs,f) fclose((f)) + #define WFREAD(fs,b,s,a,f) fread((b),(s),(a),(f)) + #define WFWRITE(fs,b,x,s,f) fwrite((b),(x),(s),(f)) + #define WFSEEK(fs,s,o,w) fseek((s),(o),(w)) + #define WFTELL(fs,s) ftell((s)) + #define WREWIND(fs,s) fseek((s), 0, IO_SEEK_SET) #define WSEEK_END IO_SEEK_END #define WBADFILE NULL @@ -275,7 +275,7 @@ extern "C" { ret = f_open(*f, filename, m); return (int)ret; } - #define WFOPEN(f, fn, m) ff_fopen((f),(fn),(m)) + #define WFOPEN(fs, f, fn, m) ff_fopen((f),(fn),(m)) #ifdef WOLFSSH_XILFATFS static inline int ff_close(WFILE *f) @@ -287,7 +287,7 @@ extern "C" { } #endif - #define WFCLOSE(f) f_close(f) + #define WFCLOSE(fs,f) f_close(f) static inline int ff_read(void *ptr, size_t size, size_t nmemb, WFILE *f) { @@ -301,7 +301,7 @@ extern "C" { } return (n_bytes / size); } - #define WFREAD(b,s,a,f) ff_read(b,s,a,f) + #define WFREAD(fs,b,s,a,f) ff_read(b,s,a,f) static inline int ff_write(const void *ptr, size_t size, size_t nmemb, WFILE *f) { FRESULT ret; @@ -314,9 +314,9 @@ extern "C" { } return (n_bytes / size); } - #define WFWRITE(b,s,a,f) ff_write(b,s,a,f) + #define WFWRITE(fs,b,s,a,f) ff_write(b,s,a,f) - #define WFTELL(s) f_tell((s)) + #define WFTELL(fs,s) f_tell((s)) static inline int ff_seek(WFILE *fp, long off, int whence) { switch(whence) { @@ -333,17 +333,17 @@ extern "C" { } return -1; } - #define WFSEEK(s,o,w) ff_seek((s),(o),(w)) + #define WFSEEK(fs,s,o,w) ff_seek((s),(o),(w)) #ifdef WOLFSSH_XILFATFS - #define WREWIND(s) ff_seek(s, WSEEK_SET, 0) + #define WREWIND(fs,s) ff_seek(s, WSEEK_SET, 0) #else - #define WREWIND(s) f_rewind(s) + #define WREWIND(fs,s) f_rewind(s) #endif #define WBADFILE (-1) #ifndef NO_WOLFSSH_DIR #define WDIR DIR #define WOPENDIR(fs,h,c,d) f_opendir((c),(d)) - #define WCLOSEDIR(d) f_closedir(d) + #define WCLOSEDIR(fs,d) f_closedir(d) #endif #elif defined(WOLFSSH_USER_FILESYSTEM) /* User-defined I/O support */ @@ -355,15 +355,15 @@ extern "C" { #define WFILE FILE WOLFSSH_API int wfopen(WFILE**, const char*, const char*); - #define WFOPEN(f,fn,m) wfopen((f),(fn),(m)) - #define WFCLOSE(f) fclose(f) - #define WFREAD(b,s,a,f) fread((b),(s),(a),(f)) - #define WFWRITE(b,s,a,f) fwrite((b),(s),(a),(f)) - #define WFSEEK(s,o,w) fseek((s),(o),(w)) - #define WFTELL(s) ftell((s)) - #define WREWIND(s) rewind((s)) - #define WSEEK_END SEEK_END - #define WBADFILE NULL + #define WFOPEN(fs,f,fn,m) wfopen((f),(fn),(m)) + #define WFCLOSE(fs,f) fclose(f) + #define WFREAD(fs,b,s,a,f) fread((b),(s),(a),(f)) + #define WFWRITE(fs,b,s,a,f) fwrite((b),(s),(a),(f)) + #define WFSEEK(fs,s,o,w) fseek((s),(o),(w)) + #define WFTELL(fs,s) ftell((s)) + #define WREWIND(fs,s) rewind((s)) + #define WSEEK_END SEEK_END + #define WBADFILE NULL #ifdef WOLFSSL_VXWORKS #define WUTIMES(f,t) (WS_SUCCESS) #else @@ -403,13 +403,13 @@ extern "C" { #ifndef _WIN32_WCE #include - #define WCHDIR(p) _chdir((p)) + #define WCHDIR(fs,p) _chdir((p)) #define WMKDIR(fs,p,m) _mkdir((p)) #endif #else #include #include - #define WCHDIR(p) chdir((p)) + #define WCHDIR(fs,p) chdir((p)) #ifdef WOLFSSL_VXWORKS #define WMKDIR(fs,p,m) mkdir((p)) #else @@ -529,8 +529,8 @@ extern "C" { #define WSTAT_T struct stat #define WRMDIR(fs,d) (NU_Remove_Dir((d)) == NU_SUCCESS)?0:1 #define WMKDIR(fs,d,m) (NU_Make_Dir((d)) == NU_SUCCESS)?0:1 - #define WSTAT(p,b) NU_Get_First((b),(p)) - #define WLSTAT(p,b) NU_Get_First((b),(p)) + #define WSTAT(fs,p,b) NU_Get_First((b),(p)) + #define WLSTAT(fs,p,b) NU_Get_First((b),(p)) #define WREMOVE(fs,d) NU_Delete((d)) #ifndef WS_MAX_RENAME_BUF @@ -553,39 +553,39 @@ extern "C" { WFILE* fNew; unsigned char buf[WS_MAX_RENAME_BUF]; - if ((ret = WFOPEN(&fOld, o, "rb")) != 0) { + if ((ret = WFOPEN(NULL, &fOld, o, "rb")) != 0) { return ret; } - if ((ret = WFOPEN(&fNew, n, "rwb")) != 0) { - WFCLOSE(fOld); + if ((ret = WFOPEN(NULL, &fNew, n, "rwb")) != 0) { + WFCLOSE(NULL, fOld); return ret; } /* read from the file in chunks and write chunks to new file */ do { - ret = WFREAD(buf, 1, WS_MAX_RENAME_BUF, fOld); + ret = WFREAD(NULL, buf, 1, WS_MAX_RENAME_BUF, fOld); if (ret > 0) { - if ((WFWRITE(buf, 1, ret, fNew)) != ret) { - WFCLOSE(fOld); - WFCLOSE(fNew); + if ((WFWRITE(NULL, buf, 1, ret, fNew)) != ret) { + WFCLOSE(NULL, fOld); + WFCLOSE(NULL, fNew); WREMOVE(NULL, n); return NUF_BADPARM; } } } while (ret > 0); - if (WFTELL(fOld) == WFSEEK(fOld, 0, WSEEK_END)) { + if (WFTELL(NULL, fOld) == WFSEEK(NULL, fOld, 0, WSEEK_END)) { /* wrote everything from file */ - WFCLOSE(fOld); + WFCLOSE(NULL, fOld); WREMOVE(NULL, o); - WFCLOSE(fNew); + WFCLOSE(NULL, fNew); } else { /* unable to write everything to file */ - WFCLOSE(fNew); + WFCLOSE(NULL, fNew); WREMOVE(NULL, n); - WFCLOSE(fOld); + WFCLOSE(NULL, fOld); return NUF_BADPARM; } @@ -634,7 +634,7 @@ extern "C" { return NU_Write(fd, (const CHAR*)buf, sz); } - #define WPWRITE(fd,b,s,o) wPwrite((fd),(b),(s),(o)) + #define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o)) #endif #ifndef WPREAD @@ -648,7 +648,7 @@ extern "C" { return NU_Read(fd, (CHAR*)buf, sz); } - #define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o)) + #define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o)) #endif static inline int wUtimes(const char* f, struct timeval t[2]) @@ -738,8 +738,8 @@ extern "C" { #define WOPENDIR(fs,h,c,d) wOpenDir((c),(d)) #endif - #define WCLOSEDIR(d) NU_Done((d)) - #define WREADDIR(d) (NU_Get_Next((d)) == NU_SUCCESS)?(d):NULL + #define WCLOSEDIR(fs,d) NU_Done((d)) + #define WREADDIR(fs,d) (NU_Get_Next((d)) == NU_SUCCESS)?(d):NULL #endif /* NO_WOLFSSH_DIR */ #elif defined(FREESCALE_MQX) @@ -801,7 +801,7 @@ extern "C" { return fopen(f, mode); } - #define WOPEN(f,m,p) wOpen((f),(m),(p)) + #define WOPEN(fs,f,m,p) wOpen((f),(m),(p)) #endif #ifndef WRMDIR @@ -980,7 +980,7 @@ extern "C" { #define WGETCWD(fs,r,rSz) wGetCwd((fs),(r),(rSz)) #endif /* WGETCWD */ - #define WCLOSE fclose + #define WCLOSE(fs,fd) fclose(fd) #ifndef WPWRITE static inline int wPwrite(WFD fd, unsigned char* buf, unsigned int sz, @@ -995,7 +995,7 @@ extern "C" { return fwrite(buf, sz, 1, fd); } - #define WPWRITE(fd,b,s,o) wPwrite((fd),(b),(s),(o)) + #define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o)) #endif #ifndef WPREAD @@ -1011,7 +1011,7 @@ extern "C" { return fread(buf, 1, sz, fd); } - #define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o)) + #define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o)) #endif #ifndef NO_WOLFSSH_DIR @@ -1109,7 +1109,7 @@ extern "C" { return 0; } - #define WCLOSEDIR(d) wCloseDir((d)) + #define WCLOSEDIR(fs,d) wCloseDir((d)) #endif /* WCLOSEDIR */ #endif /* NO_WOLFSSH_DIR */ @@ -1117,10 +1117,10 @@ extern "C" { #define WSTAT_T FILINFO #define WRMDIR(fs, d) f_unlink((d)) - #define WSTAT(p,b) f_stat(p,b) - #define WLSTAT(p,b) f_stat(p,b) + #define WSTAT(fs,p,b) f_stat(p,b) + #define WLSTAT(fs,p,b) f_stat(p,b) #define WREMOVE(fs,d) f_unlink((d)) - #define WRENAME(fd,o,n) f_rename((o),(n)) + #define WRENAME(fs,fd,o,n) f_rename((o),(n)) #define WMKDIR(fs, p, m) f_mkdir(p) #define WFD int @@ -1128,10 +1128,10 @@ extern "C" { int ff_close(int fd); int ff_pwrite(int fd, const byte *buffer, int sz); int ff_pread(int fd, byte *buffer, int sz); - #define WOPEN(f,m,p) ff_open(f,m,p) - #define WPWRITE(fd,b,s,o) ff_pwrite(fd,b,s) - #define WPREAD(fd,b,s,o) ff_pread(fd,b,s) - #define WCLOSE(fd) ff_close(fd) + #define WOPEN(fs,f,m,p) ff_open(f,m,p) + #define WPWRITE(fs,fd,b,s,o) ff_pwrite(fd,b,s) + #define WPREAD(fs,fd,b,s,o) ff_pread(fd,b,s) + #define WCLOSE(fs,fd) ff_close(fd) static inline int ff_chmod(const char *fname, int mode) { @@ -1182,19 +1182,19 @@ extern "C" { #define WSTAT_T struct _stat #define WRMDIR(fs,d) _rmdir((d)) - #define WSTAT(p,b) _stat((p),(b)) - #define WLSTAT(p,b) _stat((p),(b)) + #define WSTAT(fs,p,b) _stat((p),(b)) + #define WLSTAT(fs,p,b) _stat((p),(b)) #define WREMOVE(fs,d) remove((d)) #define WRENAME(fs,o,n) rename((o),(n)) #define WGETCWD(fs,r,rSz) _getcwd((r),(rSz)) - #define WOPEN(f,m,p) _open((f),(m),(p)) - #define WCLOSE(fd) _close((fd)) + #define WOPEN(fs,f,m,p) _open((f),(m),(p)) + #define WCLOSE(fs,fd) _close((fd)) #define WFD int int wPwrite(WFD, unsigned char*, unsigned int, const unsigned int*); int wPread(WFD, unsigned char*, unsigned int, const unsigned int*); - #define WPWRITE(fd,b,s,o) wPwrite((fd),(b),(s),(o)) - #define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o)) + #define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o)) + #define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o)) #define WS_DELIM '\\' #define WOLFSSH_O_RDWR _O_RDWR @@ -1221,11 +1221,11 @@ extern "C" { #define WSTAT_T struct stat #define WRMDIR(fs,d) rmdir((d)) - #define WSTAT(p,b) stat((p),(b)) + #define WSTAT(fs,p,b) stat((p),(b)) #ifndef USE_OSE_API - #define WLSTAT(p,b) lstat((p),(b)) + #define WLSTAT(fs,p,b) lstat((p),(b)) #else - #define WLSTAT(p,b) stat((p),(b)) + #define WLSTAT(fs,p,b) stat((p),(b)) #endif #define WREMOVE(fs,d) remove((d)) #define WRENAME(fs,o,n) rename((o),(n)) @@ -1242,12 +1242,12 @@ extern "C" { #define WOLFSSH_O_TRUNC O_TRUNC #define WOLFSSH_O_EXCL O_EXCL - #define WOPEN(f,m,p) open((f),(m),(p)) - #define WCLOSE(fd) close((fd)) + #define WOPEN(fs,f,m,p) open((f),(m),(p)) + #define WCLOSE(fs,fd) close((fd)) int wPwrite(WFD, unsigned char*, unsigned int, const unsigned int*); int wPread(WFD, unsigned char*, unsigned int, const unsigned int*); - #define WPWRITE(fd,b,s,o) wPwrite((fd),(b),(s),(o)) - #define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o)) + #define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o)) + #define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o)) #ifndef NO_WOLFSSH_DIR #include /* used for opendir, readdir, and closedir */ @@ -1255,9 +1255,9 @@ extern "C" { /* returns 0 on success */ #define WOPENDIR(fs,h,c,d) ((*(c) = opendir((d))) == NULL) - #define WCLOSEDIR(d) closedir(*(d)) - #define WREADDIR(d) readdir(*(d)) - #define WREWINDDIR(d) rewinddir(*(d)) + #define WCLOSEDIR(fs,d) closedir(*(d)) + #define WREADDIR(fs,d) readdir(*(d)) + #define WREWINDDIR(fs,d) rewinddir(*(d)) #endif /* NO_WOLFSSH_DIR */ #endif #endif /* WOLFSSH_SFTP or WOLFSSH_SCP */ diff --git a/wolfssh/test.h b/wolfssh/test.h index 52062e9f0..eda5fe549 100644 --- a/wolfssh/test.h +++ b/wolfssh/test.h @@ -719,8 +719,8 @@ static INLINE int tcp_select(SOCKET_T socketfd, int to_sec) int depth, res; WFILE* file; for(depth = 0; depth <= MAX_WOLF_ROOT_DEPTH; depth++) { - if (WFOPEN(&file, serverKeyRsaPemFile, "rb") == 0) { - WFCLOSE(file); + if (WFOPEN(NULL, &file, serverKeyRsaPemFile, "rb") == 0) { + WFCLOSE(NULL, file); return depth; } #ifdef USE_WINDOWS_API