diff --git a/apps/wolfsshd/configuration.c b/apps/wolfsshd/configuration.c index 498e93ff8..742b3388b 100644 --- a/apps/wolfsshd/configuration.c +++ b/apps/wolfsshd/configuration.c @@ -672,7 +672,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; @@ -686,7 +686,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*), @@ -698,7 +698,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; @@ -766,7 +766,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 5b0f4c314..6ec720618 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -245,22 +245,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; @@ -636,7 +636,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 e08091a46..75bd8d1fc 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -1569,7 +1569,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 @@ -1592,27 +1592,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; } @@ -1634,7 +1634,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 aed1e66a9..c034bb452 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,12 +1165,13 @@ 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"); ret = WS_FATAL_ERROR; } 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 */ } @@ -1925,7 +1926,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"); @@ -1943,9 +1944,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"); @@ -1969,11 +1970,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 @@ -1999,7 +2000,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 */ @@ -2056,7 +2057,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"); @@ -2073,7 +2074,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"); @@ -2096,21 +2097,25 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, static int _GetFileSize(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) { @@ -2134,7 +2139,7 @@ static int GetFileStats(ScpSendCtx* ctx, const char* fileName, (ctx->s.dwFileAttributes | FILE_ATTRIBUTE_READONLY ? 0 : 0200); *fileMode |= (ctx->s.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 0x4000 : 0; #else - 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 && @@ -2171,8 +2176,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) { @@ -2206,7 +2213,7 @@ static ScpDir* ScpNewDir(const char* path, void* heap) } } #else - if (WOPENDIR(NULL, heap, &entry->dir, path) != 0 + if (WOPENDIR(fs, heap, &entry->dir, path) != 0 #ifndef WOLFSSL_NUCLEUS || entry->dir == NULL #endif @@ -2221,14 +2228,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; } @@ -2249,8 +2256,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; @@ -2263,7 +2272,7 @@ int ScpPopDir(ScpSendCtx* ctx, void* heap) #ifdef USE_WINDOWS_API FindClose(entry->dir); #else - WCLOSEDIR(&entry->dir); + WCLOSEDIR(fs, &entry->dir); #endif WFREE(entry, heap, DYNTYPE_SCPDIR); } @@ -2290,8 +2299,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; @@ -2314,7 +2325,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)); @@ -2350,7 +2361,7 @@ static int FindNextDirEntry(ScpSendCtx* ctx) ((WSTRLEN(ctx->entry) == 2) && WSTRNCMP(ctx->entry, "..", 2) == 0))); #else do { - ctx->entry = WREADDIR(&ctx->currentDir->dir); + ctx->entry = WREADDIR(fs, &ctx->currentDir->dir); } while ((ctx->entry != NULL) && ( ((WSTRLEN(ctx->entry->d_name) == 1) && @@ -2462,7 +2473,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); } } } @@ -2471,7 +2482,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 { @@ -2480,7 +2491,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"); @@ -2488,16 +2499,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); } } @@ -2620,7 +2631,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"); @@ -2639,10 +2650,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); @@ -2650,7 +2661,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; } @@ -2663,7 +2674,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; @@ -2673,7 +2684,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 */ @@ -2681,7 +2692,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); } @@ -2696,7 +2707,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) @@ -2710,7 +2721,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; @@ -2746,13 +2757,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 ac2692a97..303dc5be6 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -2033,7 +2033,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; @@ -2293,14 +2293,14 @@ int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) cur = (WS_DIR_LIST*)WMALLOC(sizeof(WS_DIR_LIST), 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; } @@ -2697,7 +2697,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; } @@ -2971,7 +2971,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; } @@ -3255,7 +3255,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 */ @@ -3343,7 +3343,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) { @@ -3530,7 +3530,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; @@ -3743,7 +3743,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"); @@ -4216,10 +4216,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)); @@ -4298,7 +4298,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; } @@ -4638,12 +4638,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; } } @@ -8249,9 +8249,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; @@ -8296,7 +8296,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; @@ -8358,7 +8358,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."); @@ -8447,7 +8447,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; @@ -8461,7 +8461,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, @@ -8506,7 +8506,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 */ @@ -8550,7 +8550,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 */ @@ -8601,7 +8601,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; @@ -8624,7 +8624,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 de7de36e4..ad3edabc9 100644 --- a/wolfssh/port.h +++ b/wolfssh/port.h @@ -105,14 +105,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 @@ -130,10 +130,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; @@ -182,13 +182,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 @@ -281,7 +281,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) @@ -293,7 +293,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) { @@ -307,7 +307,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; @@ -320,9 +320,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) { @@ -339,17 +339,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 */ @@ -361,15 +361,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) #elif defined(USE_WINDOWS_API) @@ -411,13 +411,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 @@ -537,8 +537,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 @@ -561,39 +561,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; } @@ -642,7 +642,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 @@ -656,7 +656,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]) @@ -746,8 +746,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) @@ -809,7 +809,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 @@ -988,7 +988,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, @@ -1003,7 +1003,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 @@ -1019,7 +1019,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 @@ -1117,7 +1117,7 @@ extern "C" { return 0; } - #define WCLOSEDIR(d) wCloseDir((d)) + #define WCLOSEDIR(fs,d) wCloseDir((d)) #endif /* WCLOSEDIR */ #endif /* NO_WOLFSSH_DIR */ @@ -1125,10 +1125,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 @@ -1136,10 +1136,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) { @@ -1190,19 +1190,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 @@ -1229,11 +1229,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)) @@ -1250,12 +1250,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 */ @@ -1263,9 +1263,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