summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2010-09-29 03:22:24 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-29 06:17:46 -0700
commit95dd4ae4dc2a8a3b3673e60c1fa6cbdbb9409d2c (patch)
treeb46d16befe731a210b3c88e368868630a5d48938 /xlators/storage
parent9406c06522f9e8ef8ee73f6da55937cb1fa04d22 (diff)
storage/posix: prevent chmod() from getting called on symlinks
symlinks, if at all their mode can be changed (on non-linux platforms) can only be done via lchmod(). Attempting chmod on a symlink can be disastrous. Signed-off-by: Anand V. Avati <avati@amp.gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 881 (GlusterFS daemon hangs on replication of symlink (3.0.4)) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=881
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 65ff6418eb3..6399d0bc048 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -31,6 +31,7 @@
#include <libgen.h>
#include <pthread.h>
#include <ftw.h>
+#include <sys/stat.h>
#ifndef GF_BSD_HOST_OS
#include <alloca.h>
@@ -521,19 +522,37 @@ posix_stat (call_frame_t *frame,
}
static int
-posix_do_chmod (xlator_t *this,
- const char *path,
- struct iatt *stbuf)
+posix_do_chmod (xlator_t *this, const char *path, struct iatt *stbuf)
{
- int32_t ret = -1;
- mode_t mode = 0;
+ int32_t ret = -1;
+ mode_t mode = 0;
+ 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;
mode = st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type);
ret = lchmod (path, 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, mode);
}
-
+out:
return ret;
}