Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of Xpra. 

2# Copyright (C) 2021 Antoine Martin <antoine@xpra.org> 

3# Xpra is released under the terms of the GNU GPL v2, or, at your option, any 

4# later version. See the file COPYING for details. 

5 

6import os 

7import sys 

8 

9from xpra.util import parse_simple_dict 

10from xpra.os_util import WIN32 

11from xpra.scripts.config import InitException 

12from xpra.log import Logger 

13 

14log = Logger("auth") 

15 

16 

17def get_auth_module(auth_str, cwd=os.getcwd(), **auth_options): 

18 log("get_auth_module(%s, {..})", auth_str) 

19 #separate options from the auth module name 

20 #either with ":" or "," as separator 

21 scpos = auth_str.find(":") 

22 cpos = auth_str.find(",") 

23 if cpos<0 or scpos<cpos: 

24 parts = auth_str.split(":", 1) 

25 else: 

26 parts = auth_str.split(",", 1) 

27 auth = parts[0] 

28 if len(parts)>1: 

29 auth_options.update(parse_simple_dict(parts[1])) 

30 auth_options["exec_cwd"] = cwd 

31 try: 

32 if auth=="sys": 

33 #resolve virtual "sys" auth: 

34 if WIN32: 

35 auth_modname = "win32_auth" 

36 else: 

37 auth_modname = "pam_auth" 

38 log("will try to use sys auth module '%s' for %s", auth, sys.platform) 

39 else: 

40 auth_modname = auth.replace("-", "_")+"_auth" 

41 auth_mod_name = "xpra.server.auth."+auth_modname 

42 log("auth module name for '%s': '%s'", auth, auth_mod_name) 

43 auth_module = __import__(auth_mod_name, {}, {}, ["Authenticator"]) 

44 except ImportError as e: 

45 log("cannot load %s auth for %r", auth, auth_str, exc_info=True) 

46 raise InitException("cannot load authentication module '%s' for %r: %s" % (auth, auth_str, e)) from None 

47 log("auth module for '%s': %s", auth, auth_module) 

48 try: 

49 auth_class = auth_module.Authenticator 

50 auth_class.auth_name = auth.lower() 

51 return auth, auth_module, auth_class, auth_options 

52 except Exception as e: 

53 log("cannot access authenticator class", exc_info=True) 

54 raise InitException("authentication setup error in %s: %s" % (auth_module, e)) from None 

55