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#!/usr/bin/env python 

2# SECUREAUTH LABS. Copyright 2021 SecureAuth Corporation. All rights reserved. 

3# 

4# This software is provided under under a slightly modified version 

5# of the Apache Software License. See the accompanying LICENSE file 

6# for more information. 

7# 

8# Utility and helper functions for the example scripts 

9# 

10import re 

11 

12 

13# Regular expression to parse target information 

14target_regex = re.compile(r"(?:(?:([^/@:]*)/)?([^@:]*)(?::([^@]*))?@)?(.*)") 

15 

16 

17# Regular expression to parse credentials information 

18credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?") 

19 

20 

21def parse_target(target): 

22 """ Helper function to parse target information. The expected format is: 

23 

24 <DOMAIN></USERNAME><:PASSWORD>@HOSTNAME 

25 

26 :param target: target to parse 

27 :type target: string 

28 

29 :return: tuple of domain, username, password and remote name or IP address 

30 :rtype: (string, string, string, string) 

31 """ 

32 domain, username, password, remote_name = target_regex.match(target).groups('') 

33 

34 # In case the password contains '@' 

35 if '@' in remote_name: 35 ↛ 36line 35 didn't jump to line 36, because the condition on line 35 was never true

36 password = password + '@' + remote_name.rpartition('@')[0] 

37 remote_name = remote_name.rpartition('@')[2] 

38 

39 return domain, username, password, remote_name 

40 

41 

42def parse_credentials(credentials): 

43 """ Helper function to parse credentials information. The expected format is: 

44 

45 <DOMAIN></USERNAME><:PASSWORD> 

46 

47 :param credentials: credentials to parse 

48 :type credentials: string 

49 

50 :return: tuple of domain, username and password 

51 :rtype: (string, string, string) 

52 """ 

53 domain, username, password = credential_regex.match(credentials).groups('') 

54 

55 return domain, username, password