mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-22 23:23:30 -06:00
pylint: Replace deprecated cgi module
https://docs.python.org/3/library/cgi.html#module-cgi: > Deprecated since version 3.11, will be removed in version 3.13: The cgi module is deprecated (see PEP 594 for details and alternatives). Fixes: https://pagure.io/freeipa/issue/9278 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Stanislav Levin <slev@altlinux.org>
This commit is contained in:
parent
b8480549c6
commit
691b5d21af
@ -21,7 +21,7 @@ Password migration script
|
|||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import cgi # pylint: disable=deprecated-module
|
from urllib.parse import parse_qs
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
@ -80,10 +80,28 @@ def application(environ, start_response):
|
|||||||
if not content_type.startswith('application/x-www-form-urlencoded'):
|
if not content_type.startswith('application/x-www-form-urlencoded'):
|
||||||
return bad_request(start_response)
|
return bad_request(start_response)
|
||||||
|
|
||||||
form_data = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
|
try:
|
||||||
if 'username' not in form_data or 'password' not in form_data:
|
length = int(environ.get("CONTENT_LENGTH"))
|
||||||
|
except (ValueError, TypeError):
|
||||||
return bad_request(start_response)
|
return bad_request(start_response)
|
||||||
|
|
||||||
|
query_string = environ["wsgi.input"].read(length).decode("utf-8")
|
||||||
|
|
||||||
|
try:
|
||||||
|
query_dict = parse_qs(query_string)
|
||||||
|
except Exception:
|
||||||
|
return bad_request(start_response)
|
||||||
|
|
||||||
|
user_query = query_dict.get("username", None)
|
||||||
|
if user_query is None or len(user_query) != 1:
|
||||||
|
return bad_request(start_response)
|
||||||
|
username = user_query[0]
|
||||||
|
|
||||||
|
password_query = query_dict.get("password", None)
|
||||||
|
if password_query is None or len(password_query) != 1:
|
||||||
|
return bad_request(start_response)
|
||||||
|
password = password_query[0]
|
||||||
|
|
||||||
status = '200 Success'
|
status = '200 Success'
|
||||||
response_headers = []
|
response_headers = []
|
||||||
result = 'error'
|
result = 'error'
|
||||||
@ -93,8 +111,7 @@ def application(environ, start_response):
|
|||||||
api = create_api(mode=None)
|
api = create_api(mode=None)
|
||||||
api.bootstrap(context='server', confdir=paths.ETC_IPA, in_server=True)
|
api.bootstrap(context='server', confdir=paths.ETC_IPA, in_server=True)
|
||||||
try:
|
try:
|
||||||
bind(api.env.ldap_uri, api.env.basedn,
|
bind(api.env.ldap_uri, api.env.basedn, username, password)
|
||||||
form_data['username'].value, form_data['password'].value)
|
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
if err.errno == errno.EPERM:
|
if err.errno == errno.EPERM:
|
||||||
result = 'invalid-password'
|
result = 'invalid-password'
|
||||||
|
Loading…
Reference in New Issue
Block a user