mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-03 21:30:14 -05:00
Uses the NOFOLLOW option in open() to ensure to do not follow symbolic links.
This commit is contained in:
parent
322110672e
commit
b299f9d368
3 changed files with 15 additions and 4 deletions
10
handle.c
10
handle.c
|
|
@ -54,7 +54,7 @@ int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_fi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_ancestor(const char* file)
|
int handle_ancestor(const char* file)
|
||||||
{
|
{
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
char* c;
|
char* c;
|
||||||
|
|
@ -111,12 +111,13 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* opening in sequential mode in Windows */
|
/* opening in sequential mode in Windows */
|
||||||
handle->f = open(handle->path, O_RDWR | O_CREAT | O_BINARY | O_SEQUENTIAL, 0600);
|
/* do not follow links to ensure to open the real file */
|
||||||
|
handle->f = open(handle->path, O_RDWR | O_CREAT | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW, 0600);
|
||||||
|
|
||||||
/* if failed for missing permission */
|
/* if failed for missing permission */
|
||||||
if (handle->f == -1 && errno == EACCES) {
|
if (handle->f == -1 && errno == EACCES) {
|
||||||
/* retry without requesting write permission */
|
/* retry without requesting write permission */
|
||||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL);
|
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle->f == -1) {
|
if (handle->f == -1) {
|
||||||
|
|
@ -195,8 +196,9 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* opening in sequential mode in Windows */
|
/* opening in sequential mode in Windows */
|
||||||
|
/* do not follow links to ensure to open the real file */
|
||||||
pathprint(handle->path, sizeof(handle->path), "%s%s", handle->disk->dir, file->sub);
|
pathprint(handle->path, sizeof(handle->path), "%s%s", handle->disk->dir, file->sub);
|
||||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL);
|
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW);
|
||||||
|
|
||||||
if (handle->f == -1) {
|
if (handle->f == -1) {
|
||||||
/* invalidate for error */
|
/* invalidate for error */
|
||||||
|
|
|
||||||
5
handle.h
5
handle.h
|
|
@ -29,6 +29,11 @@ struct snapraid_handle {
|
||||||
struct stat st; /**< Stat info of the opened file. */
|
struct stat st; /**< Stat info of the opened file. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates all the required directories if missing.
|
||||||
|
*/
|
||||||
|
int handle_ancestor(const char* file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a file, if it's different from the specified one.
|
* Closes a file, if it's different from the specified one.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
4
mingw.h
4
mingw.h
|
|
@ -48,6 +48,10 @@
|
||||||
#define opendir windows_opendir
|
#define opendir windows_opendir
|
||||||
#define readdir windows_readdir
|
#define readdir windows_readdir
|
||||||
#define closedir windows_closedir
|
#define closedir windows_closedir
|
||||||
|
#define O_NOFOLLOW 0
|
||||||
|
#define S_ISLNK(mode) 0
|
||||||
|
#define readlink(a,b,c) -1
|
||||||
|
#define symlink(a,b) -1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic stat information.
|
* Generic stat information.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue