Skip to content

Commit

Permalink
Merge pull request #355 from pantheon-systems/yolo
Browse files Browse the repository at this point in the history
Yolo to stage: readonly in dav_open
  • Loading branch information
jerryblakley authored Apr 21, 2017
2 parents 9405ad8 + 322cbfa commit 23cd525
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/fusedav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,28 @@ static void do_open(const char *path, struct fuse_file_info *info, GError **gerr
return;
}

static bool write_flag(int flags) {
// O_RDWR technically belongs in the list, but since it might be used for files
// which are only read, I leave it out.
// O_CREAT on a file which already exists is a noop unless O_EXCL is also included.
// So, only respond if both are present.
if ((flags & O_WRONLY) || ((flags & O_CREAT) && (flags & O_EXCL)) || (flags & O_TRUNC) || (flags & O_APPEND)) {
return true;
}
return false;
}

static int dav_open(const char *path, struct fuse_file_info *info) {
struct fusedav_config *config = fuse_get_context()->private_data;
GError *gerr = NULL;

// If we are in readonly mode, and we are opening a file for writing, exit
if (use_readonly_mode() && write_flag(info->flags)) {
log_print(LOG_WARNING, SECTION_FUSEDAV_FILE, "dav_open: %s aborted; in readonly mode", path ? path : "null path");
g_set_error(&gerr, fusedav_quark(), EROFS, "aborted; in readonly mode");
return processed_gerror("dav_open: ", path, &gerr);
}

BUMP(dav_open);

if (config->grace && use_saint_mode() && ((info->flags & O_TRUNC) || (info->flags & O_APPEND))) {
Expand All @@ -1576,7 +1594,7 @@ static int dav_open(const char *path, struct fuse_file_info *info) {
info->flags |= O_RDWR;
}

log_print(LOG_INFO, SECTION_FUSEDAV_FILE, "CALLBACK: dav_open: open(%s, %x, trunc=%x)", path, info->flags, info->flags & O_TRUNC);
log_print(LOG_INFO, SECTION_FUSEDAV_FILE, "CALLBACK: dav_open: open(%s, %o, trunc=%x)", path, info->flags, info->flags & O_TRUNC);
do_open(path, info, &gerr);
if (gerr) {
int ret = processed_gerror("dav_open: ", path, &gerr);
Expand Down
2 changes: 1 addition & 1 deletion tests/readrecursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int readdirectory(char *dirname, int *dirsread, int *filesread, int *erro
else {
int bytes_read;
char rbuf [1025];
fd = open(fn, O_RDWR);
fd = open(fn, O_RDONLY);
v_printf("file: %s\n", fn);
++*filesread;
bytes_read = read(fd, rbuf, 1024);
Expand Down

0 comments on commit 23cd525

Please sign in to comment.