From 8b97f77112ac83c0b80b8bb92b6dfa535f7f20ce Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Sun, 5 Dec 2010 12:39:36 +0530 Subject: storage/posix: prevent chmod() from getting called on symlinks --- xlators/storage/posix/src/posix.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 1d3b179f6..0000973c2 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifndef GF_BSD_HOST_OS #include @@ -575,13 +576,33 @@ posix_do_chmod (xlator_t *this, const char *path, struct stat *stbuf) { - int32_t ret = -1; + int32_t ret = -1; + struct stat stat; + int is_symlink = 0; + + ret = sys_lstat (path, &stat); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "%s (%s)", path, strerror (errno)); + goto out; + } + + if (S_ISLNK (stat.st_mode)) + is_symlink = 1; ret = lchmod (path, stbuf->st_mode); if ((ret == -1) && (errno == ENOSYS)) { + /* in Linux symlinks are always in mode 0777 and no + such call as lchmod exists. + */ + if (is_symlink) { + ret = 0; + goto out; + } ret = chmod (path, stbuf->st_mode); } +out: return ret; } -- cgit