mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixes issue 39472: (#40341)
With python 3.6 spwd.getspnam returns PermissionError instead of KeyError if user does not have privileges
This commit is contained in:
parent
82f6f08712
commit
db786b846f
2 changed files with 11 additions and 0 deletions
3
changelogs/fragments/py36-spwd.yaml
Normal file
3
changelogs/fragments/py36-spwd.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- spwd - With python 3.6 spwd.getspnam returns PermissionError instead of KeyError if user does not have privileges (https://github.com/ansible/ansible/issues/39472)
|
|
@ -236,6 +236,7 @@ EXAMPLES = '''
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import errno
|
||||||
import grp
|
import grp
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
@ -646,6 +647,13 @@ class User(object):
|
||||||
return passwd, expires
|
return passwd, expires
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return passwd, expires
|
return passwd, expires
|
||||||
|
except OSError as e:
|
||||||
|
# Python 3.6 raises PermissionError instead of KeyError
|
||||||
|
# Due to absence of PermissionError in python2.7 need to check
|
||||||
|
# errno
|
||||||
|
if e.errno in (errno.EACCES, errno.EPERM):
|
||||||
|
return passwd, expires
|
||||||
|
raise
|
||||||
|
|
||||||
if not self.user_exists():
|
if not self.user_exists():
|
||||||
return passwd, expires
|
return passwd, expires
|
||||||
|
|
Loading…
Add table
Reference in a new issue