Skip to content

Commit

Permalink
#426: support options in file:
Browse files Browse the repository at this point in the history
* add trivial implementation for parseOptions (using string split)
* sanitize session_options and whitelist just 2 options for now: "compression_level" and "lz4"

git-svn-id: https://xpra.org/svn/Xpra/trunk@4557 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 18, 2013
1 parent 709fb2d commit bad2d7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/xpra/server/auth/file_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ def init(opts):


def parseOptions(s):
return {}
#ie: s="compression_level=1;lz4=0", ...
#alternatives: ast, json/simplejson, ...
if not s:
return {}
options = {}
for e in s.split(";"):
parts = e.split("=", 1)
if len(parts)!=2:
continue
options[parts[0]] = parts[1]
return options


auth_data = None
Expand Down
28 changes: 21 additions & 7 deletions src/xpra/server/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from xpra.net.protocol import Protocol, new_cipher_caps, get_network_caps
from xpra.os_util import Queue, SIGNAMES
from xpra.util import typedict
from xpra.scripts.config import parse_number, parse_bool


PROXY_QUEUE_SIZE = int(os.environ.get("XPRA_PROXY_QUEUE_SIZE", "10"))
Expand Down Expand Up @@ -190,7 +191,7 @@ def __init__(self, uid, gid, env_options, session_options, client_conn, client_s
self.uid = uid
self.gid = gid
self.env_options = env_options
self.session_options = session_options
self.session_options = self.sanitize_session_options(session_options)
self.client_conn = client_conn
self.client_state = client_state
self.cipher = cipher
Expand Down Expand Up @@ -279,13 +280,26 @@ def run(self):
finally:
self.exit_cb(self)

def sanitize_session_options(self, options):
d = {}
def number(k, v):
return parse_number(int, k, v)
OPTION_WHITELIST = {"compression_level" : number,
"lz4" : parse_bool}
for k,v in options.items():
parser = OPTION_WHITELIST.get(k)
if parser:
log("trying to add %s=%s using %s", k, v, parser)
try:
d[k] = parser(k, v)
except Exception, e:
log.warn("failed to parse value %s for %s using %s: %s", v, k, parser, e)
return d

def filter_client_caps(self, caps):
fc = self.filter_caps(caps, ("cipher", "digest", "mmap", "aliases", "compression"))
#add whitelist from session_options:
OPTION_WHITELIST = ("compression_level", )
for k,v in self.session_options.items():
if k in OPTION_WHITELIST:
fc[k] = v
fc = self.filter_caps(caps, ("cipher", "digest", "mmap", "aliases", "compression", "lz4"))
#update with options provided via config if any:
fc.update(self.session_options)
return fc

def filter_server_caps(self, caps):
Expand Down

0 comments on commit bad2d7c

Please sign in to comment.