Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All the filesystem-related W* macros accept a filesystem context pointer as first parameter #556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/wolfsshd/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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*),
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
10 changes: 5 additions & 5 deletions apps/wolfsshd/test/test_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,7 +48,7 @@ static void CleanupWildcardTest(void)
WREMOVE(0, filepath);
}
}
WCLOSEDIR(&dir);
WCLOSEDIR(NULL, &dir);
WRMDIR(0, "./sshd_config.d/");
}
}
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
18 changes: 9 additions & 9 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
Loading