From 38d57757b33983052594e14582611ef05f753581 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Thu, 10 Mar 2011 00:42:48 +0000 Subject: syncdaemon: fortify purge implementation to not do silly things like following symlinks Signed-off-by: Kaushik BV Signed-off-by: Vijay Bellur BUG: 2377 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2377 --- xlators/features/marker/utils/syncdaemon/resource.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/xlators/features/marker/utils/syncdaemon/resource.py b/xlators/features/marker/utils/syncdaemon/resource.py index dc3279d5290..6882164b9c5 100644 --- a/xlators/features/marker/utils/syncdaemon/resource.py +++ b/xlators/features/marker/utils/syncdaemon/resource.py @@ -12,7 +12,7 @@ import tempfile import threading from ctypes import * from ctypes.util import find_library -from errno import EEXIST, ENOENT, ENODATA, ENOTDIR, ELOOP +from errno import EEXIST, ENOENT, ENODATA, ENOTDIR, ELOOP, EISDIR from gconf import gconf import repce @@ -100,7 +100,17 @@ class Server(object): me_also = entries == None if not entries: try: - entries = os.listdir(path) + # if it's a symlink, prevent + # following it + try: + os.unlink(path) + return + except OSError: + ex = sys.exc_info()[1] + if ex.errno == EISDIR: + entries = os.listdir(path) + else: + raise except OSError: ex = sys.exc_info()[1] if ex.errno in (ENOTDIR, ENOENT, ELOOP): @@ -109,8 +119,9 @@ class Server(object): return except OSError: ex = sys.exc_info()[1] - if ex.errno != ENOENT: - raise + if ex.errno == ENOENT: + return + raise else: raise for e in entries: -- cgit