forked from spectrumero/tnfsd
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from trekawek/read-only
Support optional read-only mode.
- Loading branch information
Showing
7 changed files
with
121 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "auth.h" | ||
#include "tnfs.h" | ||
#include "tnfs_file.h" | ||
|
||
int RW_CMDS[] = | ||
{ | ||
TNFS_MKDIR, | ||
TNFS_RMDIR, | ||
TNFS_WRITEBLOCK, | ||
TNFS_UNLINKFILE, | ||
TNFS_CHMODFILE, | ||
TNFS_RENAMEFILE, | ||
-1, | ||
}; | ||
|
||
int RW_FLAGS = | ||
TNFS_O_WRONLY | | ||
TNFS_O_RDWR | | ||
TNFS_O_APPEND | | ||
TNFS_O_CREAT | | ||
TNFS_O_TRUNC | | ||
TNFS_O_EXCL; | ||
|
||
bool read_only; | ||
|
||
void auth_init(bool _read_only) | ||
{ | ||
read_only = _read_only; | ||
} | ||
|
||
bool is_cmd_allowed(uint8_t cmd) | ||
{ | ||
if (!read_only) | ||
{ | ||
return true; | ||
} | ||
for (int i = 0; RW_CMDS[i] != -1; i++) | ||
{ | ||
if (RW_CMDS[i] == cmd) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool is_open_allowed(char *filename, int flags) | ||
{ | ||
if (!read_only) | ||
{ | ||
return true; | ||
} | ||
return (flags & RW_FLAGS) == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef _READONLY_H | ||
#define _READONLY_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
void auth_init(bool enable_writes); | ||
|
||
bool is_cmd_allowed(uint8_t cmd); | ||
|
||
bool is_open_allowed(char *filename, int flags); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters