Skip to content

Commit

Permalink
DB URLs: Allow some special chars in password: '@' and '/'
Browse files Browse the repository at this point in the history
In the opensips-cli.cfg config file, passwords may be given in both
un-escaped and escaped forms, e.g. 'opensips@rw' or 'opensips%%40rw'
(the double '%%' is needed to avoid a configparser error).

For STDIN-given passwords, they may also be given both un-escaped and
escaped, e.g. 'opensips@rw' or 'opensips%40rw'.
  • Loading branch information
liviuchircu committed Jul 11, 2024
1 parent 66e21d2 commit 31c6fa3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions opensipscli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ class osdbAccessDeniedError(osdbError):
pass

class DBURL(object):
@staticmethod
def escape_pass(pwd):
for sym in ('@', '/'): # special symbols accepted in password
pwd = pwd.replace(sym, '%'+hex(ord('@'))[2:])
return pwd

def __init__(self, url):
arr = url.split('://')
self.drivername = arr[0].strip()
Expand All @@ -144,11 +150,11 @@ def __init__(self, url):
arr = url.split('@')
if len(arr) > 1:
# handle user + password
upass = arr[0].strip().split(':')
upass = '@'.join(arr[:-1]).strip().split(':')
self.username = upass[0].strip()
if len(upass) > 1:
self.password = ":".join(upass[1:]).strip()
url = arr[1].strip()
self.password = self.escape_pass(":".join(upass[1:]).strip())
url = arr[-1].strip()
else:
url = arr[0].strip()

Expand Down Expand Up @@ -942,7 +948,7 @@ def set_url_driver(url, driver):
@staticmethod
def set_url_password(url, password):
url = make_url(url)
url.password = password
url.password = DBURL.escape_pass(password)
return str(url)


Expand Down

0 comments on commit 31c6fa3

Please sign in to comment.