aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-01-21 01:06:44 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2011-01-21 01:06:44 -0500
commitb9bc4eaa3d73977d269161662d8a11a210ef79df (patch)
treedeb5dbeb7596a6fb0f5cbdd87db0a0f8b947e11c
parent811e03d7765001aa2da20ab37d41e1c92b4ae53b (diff)
downloadalias-b9bc4eaa3d73977d269161662d8a11a210ef79df.tar.gz
Added key management to the component server
-rw-r--r--example/zaran@alias.fr.nf.zipbin2715 -> 2729 bytes
-rw-r--r--server/object.py25
-rw-r--r--server/plugin.py16
3 files changed, 28 insertions, 13 deletions
diff --git a/example/zaran@alias.fr.nf.zip b/example/zaran@alias.fr.nf.zip
index 6bd6c57..ebe27ee 100644
--- a/example/zaran@alias.fr.nf.zip
+++ b/example/zaran@alias.fr.nf.zip
Binary files differ
diff --git a/server/object.py b/server/object.py
index 73bd96e..2c1692a 100644
--- a/server/object.py
+++ b/server/object.py
@@ -36,22 +36,34 @@ class Object:
def get_permission(self, user):
file = open(self.path + 'permissions', 'r')
for line in file:
- name, sep, perm = line.rstrip('\n').partition(' ')
+ name, perm, None = line.split()
if name == user:
return int(perm)
return 0
-
+
+ def get_key(self, user):
+ file = open(self.path + 'permissions', 'r')
+ for line in file:
+ name, perm, key = line.split()
+ if name == user:
+ if not int(perm) & READ:
+ logging.error("User {} doesn't have read access to object {}"
+ .format(user, self.hash))
+ raise PermissionError
+ return key
+ return 0
+
def get_child_list(self, user):
perm = self.get_permission(user)
- if not perm & LIST :
+ if not perm & LIST:
logging.error("User {} doesn't have the list permission for object {}"
.format(user, self.hash))
raise PermissionError
file = open(self.path + "childs", 'r')
result = []
- for line in file :
+ for line in file:
name = line.rstrip('\n')
try:
child = Object(self.owner, name)
@@ -60,15 +72,16 @@ class Object:
self.owner))
else:
permission = child.get_permission(user)
+ key = child.get_key(user)
if permission > 0:
- result.append((name, permission))
+ result.append((name, permission, key))
file.close()
return result
def get_content(self, user):
perm = self.get_permission(user)
- if not perm & READ :
+ if not perm & READ:
logging.error("User {} doesn't have read access to object {}"
.format(user, self.hash))
raise PermissionError
diff --git a/server/plugin.py b/server/plugin.py
index 1f456ef..80e9863 100644
--- a/server/plugin.py
+++ b/server/plugin.py
@@ -16,12 +16,13 @@ class AliasQuery(ElementBase):
namespace = 'alias:query'
name = 'query'
plugin_attrib = 'alias'
- interfaces = set(('node', 'type', 'content', 'permission'))
+ interfaces = set(('node', 'type', 'content', 'permission', 'key'))
sub_interfaces = set(('content', 'permission'))
- def addItem(self, node, permission = None):
+ def addItem(self, node, key, permission = None):
item = AliasItem(None, self)
item['node'] = node
+ item['key']= key
if permission is not None:
item['permission'] = str(permission)
@@ -29,7 +30,7 @@ class AliasItem(ElementBase):
namespace = 'alias:query'
name = 'item'
plugin_attrib = 'item'
- interfaces = set(('node', 'permission'))
+ interfaces = set(('node', 'permission', 'key' ))
class AliasPlugin(base.base_plugin):
@@ -62,9 +63,8 @@ class AliasPlugin(base.base_plugin):
node = iq['alias']['node']
if not node:
node = hashlib.sha1(callee).hexdigest()
-
node = Object(callee, node)
-
+
if iq['alias']['type'] == 'items':
try:
childs = node.get_child_list(caller)
@@ -74,13 +74,14 @@ class AliasPlugin(base.base_plugin):
iq.reply()
iq['alias']['type'] = 'items'
iq['alias']['node'] = node.hash
- for name, perm in childs:
- iq['alias'].addItem(name, perm)
+ for name, perm, key in childs:
+ iq['alias'].addItem(name, key, perm)
iq.send()
if iq['alias']['type'] == 'content':
try:
content = node.get_content(caller)
+ key = node.get_key(caller)
except PermissionError:
self.send_permission_error(iq, 'Permission')
else:
@@ -88,4 +89,5 @@ class AliasPlugin(base.base_plugin):
iq['alias']['type'] = 'content'
iq['alias']['node'] = node.hash
iq['alias']['content'] = content
+ iq['alias']['key'] = key
iq.send() \ No newline at end of file