From 72c57a042d9ddc8bf0b65c335e808d02e35702bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 25 Mar 2011 01:03:53 +0100 Subject: [PATCH 1/2] Allow missing owner --- radicale/__init__.py | 7 ++++++- radicale/acl/htpasswd.py | 3 +++ radicale/ical.py | 10 +++++++++- radicale/xmlutils.py | 5 +++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 905257b0..d5c477bb 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -129,7 +129,12 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): attributes = posixpath.normpath(self.path.strip("/")).split("/") if len(attributes) >= 2: path = "%s/%s" % (attributes[0], attributes[1]) - return ical.Calendar(path) + elif len(attributes) == 1: # no owner + path = attributes[0] + else: + return + + return ical.Calendar(path) def _decode(self, text): """Try to decode text according to various parameters.""" diff --git a/radicale/acl/htpasswd.py b/radicale/acl/htpasswd.py index 250ec901..2ddb9186 100644 --- a/radicale/acl/htpasswd.py +++ b/radicale/acl/htpasswd.py @@ -56,6 +56,9 @@ def _sha1(hash_value, password): def has_right(owner, user, password): """Check if ``user``/``password`` couple is valid.""" + if owner is None: # no owner - everybody is allowed + return True + for line in open(FILENAME).readlines(): if line.strip(): login, hash_value = line.strip().split(":") diff --git a/radicale/ical.py b/radicale/ical.py index f8d51e4a..076d9bef 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -135,8 +135,16 @@ class Calendar(object): def __init__(self, path): """Initialize the calendar with ``cal`` and ``user`` parameters.""" + + split_path = path.split("/") + self.encoding = "utf-8" - self.owner = path.split("/")[0] + + if len(split_path) > 1: + self.owner = split_path[0] + else: + self.owner = None + self.path = os.path.join(FOLDER, path.replace("/", os.path.sep)) @staticmethod diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index f811f7fe..88c98d0b 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -51,7 +51,7 @@ def _response(code): def name_from_path(path): """Return Radicale item name from ``path``.""" path_parts = path.strip("/").split("/") - return path_parts[-1] if len(path_parts) > 2 else None + return path_parts[-1] if len(path_parts) >= 2 else None def delete(path, calendar): @@ -129,7 +129,8 @@ def propfind(path, xml_request, calendar, depth): tag = ET.Element(_tag("D", "collection")) element.append(tag) elif tag == _tag("D", "owner"): - element.text = calendar.owner + if calendar.owner: + element.text = calendar.owner elif tag == _tag("D", "getcontenttype"): element.text = "text/calendar" elif tag == _tag("CS", "getctag") and is_calendar: From 5673444ba77e76e5c59ade8d8c043edcde969dca Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sun, 10 Apr 2011 18:51:38 +0200 Subject: [PATCH 2/2] Clean owner-less calendars support (fixes #254) --- radicale/__init__.py | 11 +++-------- radicale/acl/htpasswd.py | 3 ++- radicale/ical.py | 11 ++--------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 79689af3..c8a0794c 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -175,14 +175,9 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): # ``self.path`` must be something like a posix path # ``normpath`` should clean malformed and malicious request paths attributes = posixpath.normpath(self.path.strip("/")).split("/") - if len(attributes) >= 2: - path = "%s/%s" % (attributes[0], attributes[1]) - elif len(attributes) == 1: # no owner - path = attributes[0] - else: - return - - return ical.Calendar(path) + if attributes: + path = "/".join(attributes[:min(len(attributes), 2)]) + return ical.Calendar(path) def _decode(self, text): """Try to decode text according to various parameters.""" diff --git a/radicale/acl/htpasswd.py b/radicale/acl/htpasswd.py index 2ddb9186..422b96c6 100644 --- a/radicale/acl/htpasswd.py +++ b/radicale/acl/htpasswd.py @@ -56,7 +56,8 @@ def _sha1(hash_value, password): def has_right(owner, user, password): """Check if ``user``/``password`` couple is valid.""" - if owner is None: # no owner - everybody is allowed + if owner is None and PERSONAL: + # No owner and personal calendars, everybody is allowed return True for line in open(FILENAME).readlines(): diff --git a/radicale/ical.py b/radicale/ical.py index 076d9bef..25a1b448 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -135,16 +135,9 @@ class Calendar(object): def __init__(self, path): """Initialize the calendar with ``cal`` and ``user`` parameters.""" - - split_path = path.split("/") - self.encoding = "utf-8" - - if len(split_path) > 1: - self.owner = split_path[0] - else: - self.owner = None - + split_path = path.split("/") + self.owner = split_path[0] if len(split_path) > 1 else None self.path = os.path.join(FOLDER, path.replace("/", os.path.sep)) @staticmethod