Skip to content

Commit 5568a49

Browse files
authored
Merge pull request #18 from cognifloyd/py3
Python3 fixes
2 parents 0c43a94 + 6531930 commit 5568a49

File tree

6 files changed

+37
-18
lines changed

6 files changed

+37
-18
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
3-
- 2.7
3+
- 3.6
4+
- 3.8
45

56
# Used old infrastructure, needed for integration tests:
67
# http://docs.travis-ci.com/user/workers/standard-infrastructure/
@@ -18,8 +19,8 @@ cache:
1819
- $HOME/.cache/pip/
1920

2021
install:
21-
- sudo -H pip install tox
22-
- sudo -H pip install --upgrade pip
22+
- pip install --upgrade pip
23+
- pip install tox
2324
- if [ ${TASK} = 'integration' ]; then sudo -E ./scripts/travis/prepare-integration.sh; fi
2425

2526
script:

scripts/travis/build.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ fi
99
if [ ${TASK} == 'checks' ]; then
1010
tox -e lint
1111
elif [ ${TASK} == 'integration' ]; then
12-
sudo tox -e py27 # If we need more python versions, add them here.
12+
set -x
13+
# If we need more python versions, add them here.
14+
if [ -d /home/travis/virtualenv/python3.8/bin ]; then
15+
sudo bash -c "source /home/travis/virtualenv/python3.8/bin/activate && tox -e py38" || exit $?
16+
else
17+
sudo bash -c "source /home/travis/virtualenv/python3.6/bin/activate && tox -e py27,py36" || exit $?
18+
fi
1319
else
1420
echo "Invalid task: ${TASK}"
1521
exit 2

st2auth_pam_backend/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
'PAMAuthenticationBackend'
2222
]
2323

24-
__version__ = '0.1.0'
24+
__version__ = '0.2.0'

st2auth_pam_backend/pam_ffi.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
# Import Python Libs
2222
from __future__ import absolute_import
23-
from ctypes import CDLL, POINTER, Structure, CFUNCTYPE, cast, pointer, sizeof
23+
from ctypes import CDLL, POINTER, Structure, CFUNCTYPE, cast, sizeof, byref
2424
from ctypes import c_void_p, c_uint, c_char_p, c_char, c_int
25+
from ctypes import memmove
2526
from ctypes.util import find_library
2627

2728
from six.moves import range # pylint: disable=import-error,redefined-builtin
@@ -148,17 +149,23 @@ def my_conv(n_messages, messages, p_response, app_data):
148149
'''
149150
# Create an array of n_messages response objects
150151
addr = CALLOC(n_messages, sizeof(PamResponse))
151-
p_response[0] = cast(addr, POINTER(PamResponse))
152+
response = cast(addr, POINTER(PamResponse))
153+
p_response[0] = response
152154
for i in range(n_messages):
153155
if messages[i].contents.msg_style == PAM_PROMPT_ECHO_OFF:
154-
pw_copy = STRDUP(str(password))
155-
p_response.contents[i].resp = cast(pw_copy, c_char_p)
156-
p_response.contents[i].resp_retcode = 0
156+
dst = CALLOC(len(password) + 1, sizeof(c_char))
157+
memmove(dst, cpassword, len(password))
158+
response[i].resp = dst
159+
response[i].resp_retcode = 0
157160
return 0
158161

162+
username = username.encode('UTF-8')
163+
password = password.encode('UTF-8')
164+
service = service.encode('UTF-8')
165+
cpassword = c_char_p(password)
159166
handle = PamHandle()
160167
conv = PamConv(my_conv, 0)
161-
retval = PAM_START(service, username, pointer(conv), pointer(handle))
168+
retval = PAM_START(service, username, byref(conv), byref(handle))
162169

163170
if retval != 0:
164171
# TODO: This is not an authentication error, something

test-requirements.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
mock==3.0.5
1+
mock==3.0.5 ; python_version == '2.7'
2+
mock==4.0.3 ; python_version >= '3.6'
23
nose>=1.3.7
34
pep8==1.7.1
4-
pylint==1.9.4
5+
pylint<2 ; python_version == '2.7'
6+
pylint==2.8.2 ; python_version >= '3.6'
57
st2flake8==0.1.0
68
unittest2

tox.ini

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[tox]
2-
envlist = py27,lint
3-
#envlist = py27,py36,lint
2+
envlist = py27,py36,py38,lint
43

54
[testenv]
65
deps = -r{toxinidir}/requirements.txt
@@ -10,9 +9,13 @@ deps = -r{toxinidir}/requirements.txt
109
basepython = python2.7
1110
commands = python setup.py test
1211

13-
#[testenv:py36]
14-
#basepython = python3.6
15-
#commands = python setup.py test
12+
[testenv:py36]
13+
basepython = python3.6
14+
commands = python setup.py test
15+
16+
[testenv:py38]
17+
basepython = python3.8
18+
commands = python setup.py test
1619

1720
[testenv:lint]
1821
commands = flake8 --config ./lint-configs/python/.flake8 st2auth_pam_backend/

0 commit comments

Comments
 (0)